配置安装Struts2 web.xml文件

来源:互联网 发布:将dmp文件导入数据库 编辑:程序博客网 时间:2024/05/28 05:13

配置安装struts2.0 需要分为几步:

第一步:打开http://struts.apache.org/download.cgi地址,下载最新的struts2.0。

第二步:把struts2.0中lib中所有jar文件复制到webProject工程中的/WEB-INF/lib目录下。

第三步:把从下载下来的struts2.0目录找出struts.xml和struts.properties放到webProject工程中src目录中,通过myEclipse编译这个两个文件会编译到/WEB-INF/classes目录中。

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>
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />

    <constant name="struts.devMode" value="false" />
   <!--
    <package name="person" extends="struts-default">

        <action name="list" method="execute" class="personAction">
            <result>pages/list.jsp</result>
            <result name="input">pages/list.jsp</result>
        </action>

    </package> -->
</struts>

 

struts.properties文件中配置内容:

struts.devMode =  false(指定struts2处于开发状态)

struts.configuration.xml.reload = true(指定当struts2配置文件改变后,web框架是否重新加载struts2配置文件)

 

第四步:在WEB-INF目录下新建applicationContext.xml文件。

applicationContext.xml文件内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-autowire="autodetect">
</beans>

 

第五步:在下载的struts2.0文件查找log4j.jar包,放到/WEB-INF/lib目录下。

第六步:配置Web.xml文件

<?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">


 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/classes/applicationContext-*.xml</param-value>
 </context-param>


 <filter>
  <description>struts2</description>
  <filter-name>struct2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
 </filter>


 <filter-mapping>
  <filter-name>struct2</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>


 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>


 <servlet>

  <servlet-name>action</servlet-name>
  <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
  <init-param>
   <param-name>config</param-name>
   <param-value>/WEB-INF/struts-config.xml</param-value>

  </init-param>
  <init-param>
   <param-name>debug</param-name>
   <param-value>3</param-value>

  </init-param>
  <init-param>
   <param-name>detail</param-name>
   <param-value>3</param-value>

  </init-param>
  <load-on-startup>0</load-on-startup>
 </servlet>


 <servlet-mapping>
  <servlet-name>action</servlet-name>
  <url-pattern>*.do</url-pattern>
 </servlet-mapping>


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

 

如果在jsp文件中加了(如果在你的JSP页面中需要Struts2的标签,只需要在JSP页面中引入),不需要在Web.xml文件中配置一下代码

<%@ taglib prefix="s" uri= "/struts-tags" %>
 <jsp-config>
  <taglib>
   <taglib-uri>/s</taglib-uri>
   <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
  </taglib>
 </jsp-config>


 <login-config>
  <auth-method>BASIC</auth-method>
 </login-config>


</web-app>

 

第七步:运行程序

 

 

关于struts2.0目录说明:

apps:该文件夹下包含了基于struts2的示例应用,这些示例应用对于学习者是非常有用资料。

docs:该文件夹下包含了strut2.0的相关文档,包含strut2的快速入门,struts2快速入门,struct2的文档,以及API文档等内容。

j4:该文件夹下包含了让struts2支持JDK1.4的jar包

lib:该文件夹下包含了struts2框架的核心类库,以及struts2的第三方插件类库。

src:该文件夹下包含了struts2框架的全部源代码。

 

原创粉丝点击