ShowWords.java
package action;
import com.opensymphony.xwork2.ActionSupport;
public class ShowWords extends ActionSupport {
private String name;
private String words;
public String execute()
{
if("".equals(name))
{
return INPUT;
}
else
{
words="welcom "+name;
return SUCCESS;
}
}
}
inputWords.jsp
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><title>简单的struts 2 应用</title></head>
<body>
<center>
<form name="myForm" action="showWords.action" method="post">
请输入姓名:<input name="name" type="text" /><br/>
<input type="submit" name="mySubmit" value="提交"/>
</form>
</center>
</body>
</html>
showWords.jsp
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><title>简单的struts 2 应用</title></head>
<body>
${words}
</body>
</html>
web.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>ch2struts2</display-name>
<filter>
<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>inputWords.jsp</welcome-file>
</welcome-file-list>
</web-app>
例子是安装书上的写的,但是,总是提示错误,请大牛看看什么原因,本人菜鸟。。。
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="showWords" class="com.ShowWords">
<result name="success">/showWords.jsp</result>
<result name="error">/inputWords.jsp</result>