当前位置: 代码迷 >> Java Web开发 >> Struts1 后台如何获取不到前台的值
  详细解决方案

Struts1 后台如何获取不到前台的值

热度:10   发布时间:2016-04-16 22:16:25.0
Struts1 后台怎么获取不到前台的值
<form method="post" action="Task1.do" ">
 <table align="center">
 <tr>
 <td>UserID:</td><td><input type="text" id="user_id" name="${userInfo.UserInfo.Userid}" 
 onblur="out_chkNumber('user_id','show_UserId','ERR:UserId hava to be Number format and more than 3 digits and be number! ')" />
  <span  style="display: show" id="show_UserId" >&nbsp;</span ></td>
 </tr>
  <tr>
 <td>UserName:</td><td><input type="text" id="user_name" name="${userInfo.UserInfo.Username}" 
  onblur="out_chkLength('user_name','show_UserName','ERR:UserName length have to less than 20 digits!','0','21')" />
  <span  style="display: show" id="show_UserName" >&nbsp;</span ></td>
 </tr>
  <tr>
 <td>Group:</td><td><input type="text" id="user_group" name="${userInfo.UserInfo.Group_}" 
 onblur="out_chkLength('user_group','show_Group','ERR:Group length have to less than 10 digits!','0','11')" />
  <span  style="display: show" id="show_Group">&nbsp;</span ></td>
 </tr>
  <tr>
 <td>Telephone_No:</td><td><input type="text" id="user_telephone" name="${userInfo.UserInfo.Telephone_No}" 
 onblur="out_chkPhone('user_telephone','show_Telephone','ERR:Telephone have to fulfil telephone format!')" />
      <span  style="display: show" id="show_Telephone" >&nbsp;</span ></td>
 </tr>
  <tr>
 <td>Status:</td><td><input type="text" id="user_status" name="${userInfo.UserInfo.Status}" 
 onblur="out_chkLength('user_status','show_Status','ERR:Status have to less than 10 digits!','0','11')"  />
     <span  style="display: show" id="show_Status" >&nbsp;</span ></td>
 </tr>
   <tr>
 <td>Address:</td><td><input type="text" id="user_address" name="${userInfo.UserInfo.Address}" 
  onblur="out_chkLength('user_address','show_Address','ERR:Address have to less than 31 digits!','0','32')"  />
       <span  style="display: show" id="show_Address" >&nbsp;</span ></td>
 </tr>
<tr><td><input type="submit" value="Submit" onclick="action='Task1.do?actionMethod=saveAction'" /> </td><td><input type="reset" value="Clear"></td> </tr>
</table>

</form>

页面传入后台值是这样的吗?
我有UserInfo.class


public class Task1Action extends DispatchAction {
                    public UserInfo userInfo= new UserInfo();
public ITask1Service task1Service;

public ActionForward saveAction(ActionMapping mapping , ActionForm form ,
 HttpServletRequest request , HttpServletResponse response) throws Exception {

  

if (task1Service.findUser(userInfo.getUserid()) != null) {
task1Service.update(userInfo);

} else {
task1Service.insert(userInfo);
}

return mapping.findForward("success");
}


是不是new一个就能获取前台输入的值了啊
------解决方案--------------------
看最后,页面html 上 的 name= 这些有没有生成
------解决方案--------------------
name=“”  所以你后面取不出来值。
你的 name  里面不是死的吗? 直接   name="username"  这样不行吗?

------解决方案--------------------
你那new一个怎么可能有值,不会自动注入的。。
将actionForm强转为userinfo对象即可
------解决方案--------------------
不是应该ActionForm form?的值强转的嘛,userinfo要配置
------解决方案--------------------
看得有点晕,不过要用struts1,先要把框架搭起来:JSP、Action、ActionForm、xml配置文件
JSP中的表单元素名字与ActionForm一致
配置好xml文件后,框架会自动获取表单的值并赋给ActionForm
完成以上,应该是可以满足你的要求
  相关解决方案