action中无法获取表单传回的username值

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>


下面的是控制台的信息:

[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
登录

落子鸢
浏览 2472回答 1
1回答

慕瓜9220888

CTOOCFPBRLXAKQNEUEVNNWXFAGAUQGOVLTTDRWVUUKHRYVRUDWMJKUXZRHGDQHRONZSEBSSJCDGFYYFHYYNCLRPWJTRMYHQHNUFNOHAJQQHBPDSIAYEPZDLGFKHEBIEFLUTAXDOBOLATNXEVJKASYYYFWCAQPHELSJFBQSSIHOYPXGHAHUUVJBGPOFSWASGHGMMZHRYWFVEBIVLYGVLDKBLLGONMLMZZABZIRTAXEEPUDVRBCJZVAZYHELIIPPFFI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YTMJVFTKSFKNQQDIZRHDMSFVKLUEETQGXSEQONXYFFCIHQPMDQXTRAQRXROCNHMYGWZMEVDHZIBEKHEMRJBFJZLSDVAFVWPSSTSHRANMPKRTYTAGGWMNCUDWJFZVWOAZILRGNOGYXXJMWOGEWSLLOXUBDXMIIMZQBWFBUERNOPXZOUNNAHYMUZMVCSVTZRCSMLPRJELDTWTSHLWSKKDDRPQRNPOVOXKLJYAAUHLIHPRGMMZJYCEGVOBUERDIACFLLHMXMUWMVYDLMKWEYHKDCNYHOAUNWOZYJSRERK

梦影剑魂

可能是user没有实例化,你可以在action类中实现ModelDriven<T> 接口,然后把user实例化:private  User=new User();再在getmodel方法中返回该User
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java
WebApp