[JAVA web项目]dynamic web project部署strust2.3.24

 

first,下载eclipse-j2ee 

和 strust2:

http://struts.apache.org/download.cgi

可以考虑下载“Full Distribution”版本

1 解压strust2,挑选需要的文件

2 src根目录下新增文件struts.xml。

这里要注意 struts public是否配置正确

extends是否有配置,可以默认strusts-default

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 
 3 <!DOCTYPE struts PUBLIC
 4  "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
 5  "http://struts.apache.org/dtds/struts-2.3.dtd">
 6 
 7 <struts>
 8 
 9     <constant name="struts.enable.DynamicMethodInvocation" value="false" />
10     <constant name="struts.devMode" value="true" /> 
11     <package name="default"  extends="struts-default">
12 
13         <default-action-ref name="index" />
14         <global-results>
15             <result name="error">/error.jsp</result>
16         </global-results>
17         <global-exception-mappings>
18             <exception-mapping exception="java.lang.Exception" result="error"/>
19         </global-exception-mappings>
20 
21  
22         <action name="Login" class="action.LoginAction">
23             <result>/TestLoginResult.jsp</result>
24             <result name="input">/TestLogin.jsp</result>
25         </action>
26     </package>
27     
28 </struts>

 

3 配置web.xml

welcome-file尽量配置,不然很容易出现问题。(“There is no Action mapped for namespace...”)

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app version="2.5" 
 3 xmlns="http://java.sun.com/xml/ns/javaee" 
 4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 5 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
 6 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 
 7 
 8     <display-name>Struts Blank</display-name>
 9     <filter>
10         <filter-name>struts2test</filter-name>
11         <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
12     </filter>
13 
14     <filter-mapping>
15         <filter-name>struts2test</filter-name>
16         <url-pattern>/*</url-pattern>
17     </filter-mapping>
18     
19     <welcome-file-list>
20         <welcome-file>Test.html</welcome-file>
21     </welcome-file-list>
22 </web-app>

 

 

4 然后参考以下截图目录

 

5 新增文件TestLogin.jsp

 1 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 2     pageEncoding="ISO-8859-1"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10     <form action="Login" method="post">
11         u:<input type="text" name="user" />
12         <p />
13         p:<input type="text" name="psw" />
14         <p />
15         <input type="submit" name="sm" value="OK" />
16     </form>
17 </body>
18 </html>

 

6 新增 TestLoginResult.jsp

这个只是登录成功后显示的,可以为空。

 

7 src.action下新增LoginAction.java

在哪个目录下新增,是和struts.xml配置有关

里面的成员变量user,psw是和TestLogin.jsp中的对应的。

 1 package action;
 2 
 3 import com.opensymphony.xwork2.ActionSupport;
 4 
 5 public class LoginAction extends ActionSupport
 6 {
 7 
 8     /**
 9      * 
10      */
11     private static final long serialVersionUID = 1L;
12     public String user;
13     public String psw;
14 
15     public String getUser()
16     {
17         return user;
18     }
19 
20 
21     public void setUser(String user)
22     {
23         this.user = user;
24     }
25 
26 
27     public String getPsw()
28     {
29         return psw;
30     }
31 
32 
33     public void setPsw(String psw)
34     {
35         this.psw = psw;
36     }
37     
38     @Override
39     public String execute() throws Exception
40     {
41         // TODO Auto-generated method stub
42         if(this.user.equals("a") && this.psw.equals("b"))
43         {
44             return SUCCESS;        
45         }
46         else return INPUT;
47     }
48 
49 }

 

 

 

 

 

然后就可以调试了。

如果你发现还是不成功,查看classes输出文件是否设置正确。

 

转载于:https://www.cnblogs.com/SKeyC27/p/4626357.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值