struts2跳转出现的问题

2 篇文章 0 订阅
2 篇文章 0 订阅
我想问一下,在struts2中从action可以跳转到action否?我的代码如下:
---------------login.jsp 登录页:----------------
                <s:form action="preLogin" method="post">
<s:textfield name="username" label="username">
</s:textfield>
<s:password name="password" label="password"></s:password>
<s:submit></s:submit>
</s:form>

----------------PreLoginAction.java -------------------
private String username;
private String password;
/*getter、setter方法省略*/

public String execute() throws Exception {
ServletActionContext.getRequest().getSession().setAttribute("user", "true");
return SUCCESS;
}

@Override
public void validate() {
if(!"hello".equals(username) && username.trim().equals("") && username==null ){
this.addFieldError("username", "username wrong!!!");
} else if(!"world".equals(password) && password.trim().equals(password) && password==null){
this.addFieldError("password", "password wrong!!!");
}
}

---------------------LoginAction.java-----------------------

public String execute() throws Exception {

return SUCCESS;
}

-------------------CheckLoginInterceptor.java------------------------

public String intercept(ActionInvocation actionInvocation) throws Exception {
System.out.println("begin check login interceptor!");

// String result = actionInvocation.invoke();
//
// System.out.println("--------"+result+"--------");

// 检查Session中是否存在user
/**
* 如果结果是这样,那我该怎么想session中注入值?
*/
Map session = actionInvocation.getInvocationContext().getSession();

String username = (String) session.get("user");

if (username != null && username.length() > 0) {

// 存在的情况下进行后续操作。

System.out.println("already login!");

return actionInvocation.invoke();

} else {

// 否则终止后续操作,返回LOGIN

System.out.println("no login, forward login page!");

return Action.LOGIN;

}

}

------------------struts.xml------------------

<action name="preLogin" class="org.study.test.actions.PreLoginAction">
<result>/login.action</result>
<result name="login">/login.jsp</result>
<interceptor-ref name="defaultStack"></interceptor-ref>
</action>


<action name="login" class="org.study.test.actions.LoginAction">
<result>/success.jsp</result>

<interceptor-ref name="checkLogin" />

<interceptor-ref name="defaultStack" />
</action>


-------------------下面阐述我的问题:-----------------------
当我直接访问http://localhost:8080/test/login.action的时候没错,但是我访问http://localhost:8080/test/login.jsp的时候,它
本来应该跳转到PreLoginAction然后跳转到LoginAction的,但是却出错了,

页面的错误如下:

HTTP Status 404 - /test/login.action

type Status report

message /test/login.action

description The requested resource (/test/login.action) is not available.

------------------控制台没有报错,有些警告,如下:-------------------------

2009-8-28 1:29:52 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-default.xml]
2009-8-28 1:29:53 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Unable to locate configuration files of the name struts-plugin.xml, skipping
2009-8-28 1:29:53 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-plugin.xml]
2009-8-28 1:29:53 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts.xml]
2009-8-28 1:30:08 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: No configuration found for the specified action: 'preLogin' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
2009-8-28 1:30:10 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: No configuration found for the specified action: 'preLogin' in namespace: ''. Form action defaulting to 'action' attribute's literal value.

希望高手帮我解决下,谢谢!


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值