HelloWorld.jsp:
- <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
- pageEncoding="ISO-8859-1"%>
- <%@ taglib prefix="s" uri="/struts-tags"%>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
- <title>Hello World!>
- </head>
- <body>
- <h2><s:property value="messageStore.message" /></h2>
- </body>
- </html>
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="true" />
- <package name="default" extends="struts-default">
- <action name="index">
- <result>/index.jsp</result>
- </action>
- <action name="hello" class="org.apache.struts.helloworld.action.HelloWorldAction" method="execute">
- <result name="success">/HelloWorld.jsp</result>
- </action>
- </package>
- </struts>
web.xml:
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns:xsi="" xmlns="" xmlns:web="/web-app_2_5.xsd" xsi:schemaLocation=" /web-app_2_5.xsd" id="WebApp_ID" version="2.5">
- <display-name>strutstest</display-name>
- <welcome-file-list>
- <welcome-file>index.html</welcome-file>
- <welcome-file>index.htm</welcome-file>
- <welcome-file>index.jsp</welcome-file>
- <welcome-file>default.html</welcome-file>
- <welcome-file>default.htm</welcome-file>
- <welcome-file>default.jsp</welcome-file>
- </welcome-file-list>
- <filter>
- <filter-name>struts2</filter-name>
- <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
- <!--<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>-->
- </filter>
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- </web-app>
新建动态Web工程(或者安装Tomcat插件后新建Tomcat工程),然后书写上面的代码并引入必要的Struts2的库,发布运行你就可以成功了!
阅读(4184) | 评论(0) | 转发(0) |