我想在jsp页面上传一个参数过去,在action中接收,我的代码是
<html:hidden property="username" value="john"/>
我测试时在action中获取到的数据是null
其中action中的代码为:
Showform show=(Showform)form;
System.out.println("37===="+request.getParameter("newsTypeName"));
show.setNewsTypeName(request.getParameter("newsTypeName"));
String str=show.getNewsTypeName();
System.out.println("showaction.java 38 "+str);
在actionform中的代码为:
private String username;
private String password;
private String newsTypeName;
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
// Validate an attribute named "xxx"
//if( getXXX() == null || getXXX().length() == 0 )
// errors.add("xxx",new ActionMessage("errors.required","xxx"));
return errors;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
super.reset(mapping, request);
} public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public String getNewsTypeName() {
return newsTypeName;
} public void setNewsTypeName(String newsTypeName) {
this.newsTypeName = newsTypeName;
}
<html:hidden property="username" value="john"/>
我测试时在action中获取到的数据是null
其中action中的代码为:
Showform show=(Showform)form;
System.out.println("37===="+request.getParameter("newsTypeName"));
show.setNewsTypeName(request.getParameter("newsTypeName"));
String str=show.getNewsTypeName();
System.out.println("showaction.java 38 "+str);
在actionform中的代码为:
private String username;
private String password;
private String newsTypeName;
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
// Validate an attribute named "xxx"
//if( getXXX() == null || getXXX().length() == 0 )
// errors.add("xxx",new ActionMessage("errors.required","xxx"));
return errors;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
super.reset(mapping, request);
} public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public String getNewsTypeName() {
return newsTypeName;
} public void setNewsTypeName(String newsTypeName) {
this.newsTypeName = newsTypeName;
}
form.getUsername()
<html:hidden property="username" value="john"/>
紅色部分的名字要對應
要在后台用username 去 同楼上上的
这样属性才能完全匹配.
在action里面,通过你form的get***()方法,就可以获得你的表单里面的值了.
我测试时在action中获取到的数据是null
其中action中的代码为:
Showform show=(Showform)form;
System.out.println("37===="+request.getParameter("newsTypeName"));
show.setNewsTypeName(request.getParameter("newsTypeName"));
String str=show.getNewsTypeName();
username属性 的值为"john".newsTypeName属性并没有看见你赋值。so ,String str=show.getNewsTypeName(); 得到的结果应该是NULL
另外,我想你是想取得username属性 的值。
你应该修改为String str=show.getUsername();