救救孩子吧,快疯了
tomcat7.0.105
struts2.2.3.1
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.4">
<filter>
<!-- Filter名称 -->
<filter-name>struts2</filter-name>
<!--Filter入口 -->
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<!-- Filter名称 -->
<filter-name>struts2</filter-name>
<!-- 截获的所有URL-->
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<!-- 开始页面 -->
<welcome-file>index.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 Congfiguration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<!--指定struts.xml文件的根元素-->
<struts>
<!--配置包,包名为default,
该包继承了Struts 2框架的默认包struts-default-->
<package name="default" namespace="/" extends="struts-default">
<!--定义名为hello的Action,该Action的处理类为com.action.TestAction,
并映射到success.jsp页面-->
<action name="hello" class="com.action.TestAction">
<result>/success.jsp</result>
</action>
</package>
</struts>
struts.propertoes
<struts.i18n.encoding value="UTF-8"/>
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset= ">
<title>Insert title here</title>
</head>
<body>
<!--a标签-->
<s:a action="hello">hello</s:a>
</body>
</html>
success.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<body>
<!--输出helo值-->
<s:property value="helo"/>
</body>
</body>
</html>
TestAction.java
package com.action;
import com.opensymphony.xwork2.ActionSupport;
public class TestAction extends ActionSupport{
private static final long serialVersionUID=1L;
private String helo; //Action属性
//getter方法
public String getHelo() {
return helo;
}
//setter方法
public void setHelo(String helo) {
this.helo = helo;
}
//重载execute()方法
public String execute() throws Exception {
helo="hello,world";
return SUCCESS;
}
}