Eclipse helios 配置Struts2图解


  1. <?xml version="1.0" encoding="GBK" ?>  
  2. <!DOCTYPE struts PUBLIC  
  3.     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  
  4.     "http://struts.apache.org/dtds/struts-2.0.dtd">  
  5.   
  6. <struts>  
  7.       
  8. </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]
  1. <?xml version="1.0" encoding="GBK"?>  
  2. <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">  
  3.   <filter>  
  4.     <filter-name>struts2</filter-name>  
  5.     <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>  
  6.   </filter>  
  7.   <filter-mapping>  
  8.     <filter-name>struts2</filter-name>  
  9.     <url-pattern>/*</url-pattern>  
  10.   </filter-mapping>  
  11. </web-app>  


6.编写struts.xml

[html]
  1. <?xml version="1.0" encoding="GBK" ?>  
  2. <!DOCTYPE struts PUBLIC  
  3.     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  
  4.     "http://struts.apache.org/dtds/struts-2.0.dtd">  
  5.   
  6. <struts>  
  7.       
  8. </struts>  
     

编写Hello world

1.创建一个Hello.jsp 并且内容为Hello struts2!!!

2.配置struts.xml

[html]
  1. <struts>  
  2.     <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>  
  3.     <package name="HelloPackage" namespace="/" extends="struts-default">  
  4.         <action name="Hello">  
  5.             <result>/Hello.jsp</result>  
  6.         </action>  
  7.     </package>  
  8. </struts>  

3.部署并在浏览器中填写  http://localhost:8888/StrutsDemo01/Hello

相关内容