---
title: "在Eclipse下实践Struts(不用Struts IDE) 二"
author: "utyphoon"
date: "2008-09-26T10:47:36Z"
tags: []
categories: ["非技术"]
slug: "eclipse-struts-struts-ide"
draft: false
lastmod: "2008-09-26T10:47:36Z"
id: 246952
url: "https://ujava.iteye.com/blog/246952"
---

改了一下，只贴代码了：
web.xml

```xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>utest</display-name>
<filter>
<display-name>struts2</display-name>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>
```


index.jsp

```html

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>你好，世界</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<form action="hello.action" method="post">
<fieldset><legend>Struts2入门实例</legend>
<p><label>请输入你想说的话：</label>
<input type="text" name="helloWorld" value="buddy" /></p>
<p><input type="submit" value="提交" /></p>
</fieldset>
</form>
</body>
</html>
```


success.jsp

```html

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>成功啦</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">  
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
</head>

<body>
    <s:property value="helloWorld" /> <br>
</body>
</html>

```


struts.xml

```xml

<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <include file="struts-default.xml" />

    <package name="default" extends="struts-default">
        <action name="hello"
            class="com.yeepal.test.HelloAction">
            <result name="success">success.jsp</result>
            <result name="input">index.jsp</result>
        </action>

    </package>
</struts>

```


HelloAction.java

```java

package com.yeepal.test;

import com.opensymphony.xwork2.ActionSupport;

public class HelloAction extends ActionSupport {
    private static final long serialVersionUID = 1L;

    private String helloWorld;
   
    public String getHelloWorld() {
        return helloWorld;
    }

    public void setHelloWorld(String helloWorld) {
        this.helloWorld = helloWorld;
    }

    public String execute() throws Exception {
        return SUCCESS;
    }
}
```