日期:2014-05-18  浏览次数:20783 次

actionform怎么取不到值
代码有点长,马上结贴
form:
<form   method= "post "   name= "Login_Form "   action= "Logon.do ">
<div>
用户名 <input   type= "text "   id= "jsp_username "   name= "jsp_username "
size= "15 "   style= "height:19px "   class= "Txtinput "> 密码 <input   type= "text "   id= "jsp_password "   name= "jsp_password "
size= "15 "   class= "Txtinput "> 验证码 <input   type= "text "   id= "jsp_checkcodes "   name= "jsp_checkcodes "
size= "6 "   class= "Txtinput ">
<img   src= "inc/checkcodes.jsp "   align= "absbottom "   width= '40 '   height= "20 ">
<input   type= "checkbox "   name= "isauto "> 自动登录 <input   type= "Submit "   id= "jsp_login "   value= "登   录 "
onclick= "return   checkForm(); "   style= "HEIGHT:   19px; "> <input   type= "button "   style= "HEIGHT:   19px; "   id= "jsp_reg "
value= "注   册 "   onclick= "top.right.location.href= 'jsp_register.jsp ' "> <input   type= "button "   style= "HEIGHT:   19px; "   id= "jsp_reg "
value= "掉线自救 "   onclick= "top.right.location.href= 'jsp_clsonline.jsp ' ">
</div>
</form>
LogonForm.java:
package   com.logon.app;

import   javax.servlet.http.*;
import   org.apache.struts.action.*;


public   class   LogonForm   extends   ActionForm   {

private   String   cnid;

private   String   jsp_username;

private   String   jsp_password;

private   String   jspScore;

private   String   jspRegtime;

private   String   jspLastuptime;

private   String   jspGroup;

private   String   jsp_checkcodes;

private   boolean   isauto   =   false;

ActionForm.java;
public   class   LogonAction   extends   Action   {
public   ActionForward   execute(ActionMapping   actionMapping,
ActionForm   actionForm,   HttpServletRequest   request,
HttpServletResponse   response)   throws   Exception   {
LogonForm   form   =   (LogonForm)   actionForm;
ActionErrors   errors   =   new   ActionErrors();
String   username   =   form.getJspUserid();
String   password   =   form.getjspPassword();

这样竟然取不到到username的值为null;

------解决方案--------------------
ActionForm
要遵守JavaBean的规范

getjspPassword

所有的Getter Setter

比如你有一个属性 jsp_password

就应该定义


public StringgetJsp_password()



public void setJsp_password(String jsp_password )

注意set get后第一个字母大写
------解决方案--------------------
formbean里面必须有属性的GET