一、Eclipse helios 配置struts2图解

原文链接:http://blog.csdn.net/xiazdong/article/details/7214967



本文章环境:

1. Eclipse for JavaEE developer   Helios

2. Struts 2.3.1.1

3. tomcat 7.0.6

配置前提:配置好tomcat,本文省略配置tomcat步骤


其实MyEclipse和Eclipse for JavaEE 的配置过程差不多,唯一的区别在于:

Eclipse for JAVAEE创建 Dynamic Web Projec;

MyEclipse创建的是Web Project;


 

1、创建一个Dynamic Web Project


 

2.点击next



 

3.看到output folder为build\classes,和传统的WEB-INF\classes有所差别,但是开发时不需要注意;


 

4.

在WEB-INF中配置web.xml,为了将Struts2框架添加入WEB应用;

在src中配置struts.xml(Eclipse在编译时会将src目录下的除了Java文件外的其他文件全部拷贝进WEB-INF\classes)

将struts核心类库导入WEB-INF\lib中;



 

5.编写web.xml


此处配置的目的是为了将struts2框架融入web应用,此处配置了一个过滤器,从前面学习可以知道,过滤器的作用是在Servlet执行之前完成一些事情,从<url-pattern>中可以看出任意的请求都会进入struts2的框架的范畴;

[html]  view plain copy
  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]  view plain copy
  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]  view plain copy
  1. <struts>  
  2.     <constant name="struts.devMode" 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

 

注意:在以后的开发中必须在<struts>元素中添加:

<constant name="struts.devMode" value="true"></constant>

因为这表明是在开发者模式,是指发生错误时提供更多的提示信息;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值