struts2框架中jsp页面向action传值出现 Error setting expression 'keyWord' with value ['dd', ]
jsp页面:
<form action="<%=context %>/from/find!findproduct" method="post">
搜索框:<input type="text" name="keyWord" id="keyWord"><br>
<input type="submit" value="提交">
<input type="reset" value="重置">
<input type="button" value="测试" onclick="bclick()">
</form>
action:
--
System.out.println("查询的关键字"+keyWord);
int maxpage = this.productService.maxFindSize(keyWord);
配置了keyWord的get,set方法,但是取到的值是null,报错如下:
20:04:52,887 ERROR ParametersInterceptor:34 - Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'keyWord' on 'class com.cn.shop.action.FindAction: Error setting expression 'keyWord' with value ['dd', ]
查询的关键字null
各种尝试之后,还是取值为null,因为只需要传一个数值过来,所以最后编写的代码如下;
this.request = ServletActionContext.getRequest();
//System.out.println("this.request**********************"+this.request);
keyWord=this.request.getParameter("keyWord");
System.out.println("查询的关键字"+keyWord);
int maxpage = this.productService.maxFindSize(keyWord);
成功的取到了值。这种方法适用于取得值不多的情况下,如果要取很多的值过来,这种方法肯定是不适合的。
后面需要研究为什么会取不到值?

浙公网安备 33010602011771号