当前位置: 代码迷 >> J2EE >> JSP 页面 的<form action=">交付的 数据 在ActionForm中 获取为NULL?
  详细解决方案

JSP 页面 的<form action=">交付的 数据 在ActionForm中 获取为NULL?

热度:976   发布时间:2016-04-19 22:41:15.0
JSP 页面 的<form action=">提交的 数据 在ActionForm中 获取为NULL??
<form action="<%=request.getContextPath() %>/querystu.do?select=chuan" method="post">
<div>Input Student Name:</div><input type="text" name="qsname"/>  <input type="submit" value="chaxun"/><br/>
</form>
</body>
</html>


----------
public ActionForward query(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
PrintWriter out=response.getWriter();
out.print("NUll???????????//"+request.getAttribute("qsname"));
return null;
}

----------
public class QSForm extends ActionForm {

private String qsname;

public String getQsname() {
return qsname;
}

public void setQsname(String qsname) {
this.qsname = qsname;
}


}
--------------------------

运行后 :NUll???????????//null


请帮帮解决下








------解决方案--------------------
<form action="<%=request.getContextPath() %>/querystu.do?select=chuan" method="post">
querystu.do?select=chuan
你用的是struts1是吧!
用select接收值,在action中封装select 这样就可以得到你传过来的值chuan了

或者用bean
假设:一个student bean 属性 name age sex
bean中封装 name age sex 如果用 hibernate 会自动封装
jsp的action提交的时候可以写个隐藏的text text的name=student.name
只要在action中封封装一下bean get一下就好了 不需要set
  相关解决方案