public?class?User?{
?private?String?userName;
?private?String?password;
?public?String?getuserName()?{
??return?userName;
?}
?public?void?setuserName(String?name)?{
??this.userName?=?name;
?}
?public?String?getPassword()?{
??return?password;
?}
?public?void?setPassword(String?password)?{
??this.password?=?password;
?}
?
}public class UserAction {?private User user;??public User getUser() {??return user;?}?public void setUser(User user) {??this.user = user;?}?public String login(){??ActionContext context = ActionContext.getContext();??Map<String, Object> session= context.getSession();????session.put("userName", user.getuserName());??System.out.println(user.getuserName());??System.out.println("登錄");??return Action.SUCCESS;?}}<struts>??? <constant name="struts.enable.DynamicMethodInvocation" value="false" />?? ??? <constant name="struts.devMode" value="true" />??? <package name="default" namespace="/" extends="struts-default">??<action name="user_*" class="jsh.struts.action.UserAction" method="{1}" >???<result name="success">????success.jsp???</result>???<result name="error">????fail.jsp???</result>??</action>??<action name="helloworld" class="jsh.struts.action.UserAction">???<result>????index.jsp???</result>??</action>??? </package></struts>表單<form action="user_login" class="jsh.struts.action.UserAction">?? 用戶名:<input? type="text" value="" name="user.userName"><br/>?? 密碼:<input type="text" name="user.password"><br/>?? <input type= "submit" value = "登錄">??</form>下面的是控制臺(tái)的信息:[http-nio-8080-exec-2] ERROR com.opensymphony.xwork2.interceptor.ParametersInterceptor - Developer Notification (set struts.devMode to false to disable this message):Unexpected Exception caught setting 'user.userName' on 'class jsh.struts.action.UserAction: Error setting expression 'user.userName' with value ['jia', ]null登錄
1 回答

夢(mèng)影劍魂
TA貢獻(xiàn)66條經(jīng)驗(yàn) 獲得超21個(gè)贊
可能是user沒(méi)有實(shí)例化,你可以在action類中實(shí)現(xiàn)ModelDriven<T> 接口,然后把user實(shí)例化:private ?User=new User();
再在getmodel方法中返回該User
添加回答
舉報(bào)
0/150
提交
取消