你好,游客 登录 注册 搜索
背景:
阅读新闻

Struts2环境搭建以及第一个应用

[日期:2013-01-20] 来源:Linux社区  作者:howlaa [字体: ]

环境搭建:

1、准备所需的JAR包:

注意,下载的sturts2下有很多的JAR包。不要全部拷过去,因为里面有很多的第三方JAR包。如果没有导入第三方JAR包导入依赖的JAR包,则会报错。

2、在WEB.XML中配置sturts2启动代码:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
 xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 <filter>
  <filter-name>struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class><!-- 注意在2.1.3以上版本需使用此class -->
 </filter>
 <filter-mapping><!-- 配置url路径 -->
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter的init方法会在web-inf/classes下寻找struts.xml配置文件。我们还未建立此文件,因此。下一步我们将建立此文件。

3、建立sturts.xml配置文件

上面说道StrutsPrepareAndExecuteFilter的Init在web-inf/calsses下寻找sturs.xml文件,而我们只需要在src目录下建立此文件即可。编译后会自动输出到classese目录下:

struts.xml配置文件:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">


<struts>
 
</struts>

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款