HelloWorld--------Struts2

1、新建一Web工程Struts2_1。

2、添加jar包(Struts2.08示例struts2-blank-2.0.8中的jar包拷进即可)。

     工程结构如图:

3、在src下新建Struts.xml文件。

struts.xml 代码
  1. <!DOCTYPE struts PUBLIC   
  2.         "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"   
  3.         "http://struts.apache.org/dtds/struts-2.0.dtd">  
  4. <struts>  
  5.     <include file="struts-default.xml" />  
  6. </struts>  

4、修改web.xml文件: 

web.xml 代码
  1. <?xml version="1.0" encoding="ISO-8859-1"?>  
  2. <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"    
  3. "http://java.sun.com/dtd/web-app_2_3.dtd">  
  4.   
  5. <web-app>  
  6.     <display-name>struts2 hello world</display-name>  
  7.     <filter>  
  8.         <filter-name>struts2</filter-name>  
  9.         <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>    
  10.     </filter>  
  11.     <filter-mapping>  
  12.         <filter-name>struts2</filter-name>  
  13.         <url-pattern>/*</url-pattern>  
  14.     </filter-mapping>  
  15.     <welcome-file-list>  
  16.         <welcome-file>index.html</welcome-file>  
  17.     </welcome-file-list>  
  18. </web-app>  

5、新建index.html页面:

index.html 代码
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  2. <html>  
  3.   <head>  
  4.     <title>index.html</title>  
  5.   </head>     
  6.   <body>  
  7.     <h3>Hello,world</h3>  
  8.   </body>  
  9. </html>  

6、启动eclipse,访问 http://127.0.0.1/Struts2_1即可。

原创:敬请赐教


你可能感兴趣的:(apache,eclipse,Web,xml,struts)