web.xml 配置
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. -->
<web-app version="2.4" xmlns="" xmlns:xsi="" xsi:schemaLocation=" /web-app_2_4.xsd"> <display-name>hello</display-name> <distributable />
<filter> <filter-name>struts-cleanup</filter-name> <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class> </filter> <filter-mapping> <filter-name>struts-cleanup</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
<filter> <filter-name>struts</filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class> </filter> <filter-mapping> <filter-name>struts</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.html</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" "">
<struts> <constant name="struts.devMode" value="false" /> <constant name="struts.action.extension" value="html" /> <package name="eicp" namespace="/" extends="struts-default">
<action name="index" class="HelloWorld"> <result name="sucess">/resource/index.jsp</result> </action>
</package>
</struts>
|
HelloWorld 类
public class HelloWorld { private static final String Message="Hello World"; private static final String SUCCESS = "sucess";
public String getMessage() { return Message; } public String execute ( ) { return SUCCESS; } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub
}
}
|
index.jsp 使用的视图文件
<%@taglib prefix="s" uri="/struts-tags" %> <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html xmlns=""> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Insert title here</title> </head> <body> <s:property value="getMessage()"/>
<a href="">index</a> <br/>
</body> </html>
|
阅读(1917) | 评论(0) | 转发(0) |