问一下关于struts的JSP中跳转到自己的问题
这个是关于login的struts的配置。
<action
attribute="loginForm"
name="loginForm"
parameter="method"
path="/login"
scope="session"
type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="register" path="/JSP/register.jsp" />
<forward name="error" path="/JSP/login.jsp" redirect="true"/>
<forward name="success" path="/JSP/success.jsp" />
</action>
这个是LoginAction
if(userService.validate(username, userpass)) {
request.setAttribute("username", username + " " + aaa);
request.setAttribute("error", "OK");
actionPath = "success";
}
else {
request.setAttribute("error", "error");
actionPath = "error";
}
奇怪的是,当成功登录时,转到success.jsp,success.jsp可以正确得到request里面的username属性,并显示。
而当登录失败时,跳转路径是自己,自己却不能得到它的error值,必须要在上面把scope设为session,
下面用session.getAttribute才能得到,这是为什么?
为什么request里面的东西转发回自己就丢掉了?
另,那个redirect是什么作用?我只是乱加的,好像在这里没有作用。