您的位置:首页 > 编程语言 > Java开发

struts2.2.1配置详解

2010-10-27 09:08 441 查看
1、下载 struts.2.2.1 下载地址自己baidu.com去。

2、打开struts2-2.2.1-all/struts-2.2.1/lib/   目录,复制





打开struts2-2.2.1-all/struts-2.2.1/apps/ 目录下随便一个.war 文件 用解压软件





找到 javassist.jar 和上面找到的 .jar 文件一起复制到 WEB-INF/lib 下。

 

3、修改 WEB-INF/web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
 xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
 
  <filter>
  <filter-name>struts22</filter-name>
  <filter-class>
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  </filter-class>
</filter>

<filter-mapping>
 <filter-name>struts22</filter-name>
 <url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

 

4、在src 下创建  strust.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>
 <package name="struts2" extends="struts-default">
 
     <action name="login" class="org.test.action.LoginAction" >
      <result name="success">/result.jsp</result>
     </action>
 </package>
</struts>

5、修改 tomcat/conf/server.xml

 

添加:<Context path="/struts22" docBase="d:/www/java/struts22/WebRoot" />

 

创建jsp文件测试

index.jsp

---------------------------------------------------------

 <body>
     <form method="POST" action="login.action">
     userName :<input type="text" name="username" />
     password :<input type="text" name="password" />
     age   :<input type="text" name="age" />
     
     <input type="submit" value="login" />
    </form>
  </body>

-------------------------------------------------------------

result.jsp

  <body>
  userName  : ${requestScope.username }
  password  : ${requestScope.password }
  age  : ${requestScope.age }
  </body>

---------------------------------------------------------------

测试地址:http://localhost:8080/struts22/

结果:userName : password : 11111111 age : 111111
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息