请æ±çèµæº[/Strutsdemo/]ä¸å¯ç¨
ææå©åå§ï¼å¿«ç¯äº
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;
}
}