- <?xml version="1.0" encoding="GBK" ?>
- <!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
- "http://struts.apache.org/dtds/struts-2.0.dtd">
-
- <struts>
-
- </struts>
本文章環境:
1. Eclipse for JavaEE developer Helios
2.Struts 2.3.1.1
3. tomcat 7.0.6
配置前提:配置好tomcat,本文省略配置tomcat步驟
1、創建一個Dynamic Web Project
2.點擊next
3.看到output folder為build\classes,和傳統的WEB-INF\classes有所差別;
4.
配置web.xml在WEB-INF中;
配置struts.xml在src中;
將struts核心類庫導入WEB-INF\lib中;
5.編寫web.xml
[html]
- <?xml version="1.0" encoding="GBK"?>
- <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
- <filter>
- <filter-name>struts2</filter-name>
- <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>
6.編寫struts.xml
[html]
- <?xml version="1.0" encoding="GBK" ?>
- <!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
- "http://struts.apache.org/dtds/struts-2.0.dtd">
-
- <struts>
-
- </struts>
編寫Hello world
1.創建一個Hello.jsp 並且內容為Hello struts2!!!
2.配置struts.xml
[html]
- <struts>
- <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
- <package name="HelloPackage" namespace="/" extends="struts-default">
- <action name="Hello">
- <result>/Hello.jsp</result>
- </action>
- </package>
- </struts>
3.部署並在浏覽器中填寫 http://localhost:8888/StrutsDemo01/Hello