用action接收参数的另一种方法就无法正常执行
如果我将User封装到一个类里,我去调用User这个类。为什么即使输入正确的值也判断错误。action接收参数不是说可以这样的吗?我再jsp也做了改动的。
<struts> < package name="default" extends="struts-default" namespace="/"> <!-- 注册拦截器 --> <interceptors> <interceptor name="MyInterceptor" class="cotruts.Interceptor.LonginInterceptor"> </interceptor> <!-- 注册拦截器栈 --> <interceptor-stack name="Mystack"> <!-- 默认拦截器 --> <interceptor-ref name="defaultStack"></interceptor-ref> <!-- 自定义拦截器 --> <interceptor-ref name="MyInterceptor"></interceptor-ref> </interceptor-stack> </interceptors> <action name="auth"> <result>/WEB-INF/page/man.jsp</result> <result name="longin">/longin.jsp</result> <!-- 引用拦截器栈 --> <interceptor-ref name="Mystack"></interceptor-ref> </action> <action name="LonginAction" class="com.struts.Action.LonginAction" method="longin"> result name="success">/WEB-INF/page/man.jsp</result> <result name="error">/longin.jsp</result> </action> </package> </struts>
public class LonginAction extends ActionSupport implements SessionAware { private User user; private Map<String,Object> session; public void setSession(Map<String, Object> session) { this.session = session; } /*** @return the user*/ public User getUser() { return user; } /*** @param user the user to set*/ public void setUser(User user) { this.user = user; } public String longin(){ if("admin".equals(user.getUsername())&&"123".equals(user.getPassowrd())){ session.put("longinInfo",user.getUsername()); return SUCCESS; }else{ session.put("longinError", "用户名或密码错误"); return ERROR; } } }
<form action="LonginAction" method="post"> 用户名:<input type="text" name="user.username"/><br/> 密码:<input type="password" name="user.password"/><br/> 登陆:<input type="submit" value="登陆"/>