ActionForm中取得的String为什么不能传到另外一个方法中作为参数,非常诡异的问题

时间:2008-06-12 08:11:49   来源:论坛整理  作者:  编辑:chinaitzhe
这是一个ActionForm
package lib.struts.core;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.*;


public class SqActionForm extends ActionForm{

private String queryname ="";
private String querymode ="";
private String keyword="";

public String getQueryname() {
return queryname;
}
public void setQueryname(String queryname) {
this.queryname = queryname;
}
public String getQuerymode() {
return querymode;
}
public void setQuerymode(String querymode) {
this.querymode = querymode;
}
public String getKeyword() {
return keyword;
}
public void setKeyword(String keyword) {
this.keyword = keyword;
}

public void reset(ActionMapping mapping,HttpServletRequest request){
super.reset(mapping, request);
setKeyword("");
setQuerymode("");
setQueryname("");
}


}
这是是Action
public class SqAction extends Action{

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
SqActionForm sqForm = (SqActionForm)form;
String keyword=sqForm.getKeyword();
String querymode=sqForm.getQuerymode();
String queryname=sqForm.getQueryname();

System.out.println(keyword.getClass().toString());

ArrayList <Bookinfo> bookList=new ArrayList <Bookinfo>();

bookList=JUtil.simpleQuery("java", "1","will"); //问题是这个,我用这种方法是没有问题的,直接显示出来结果
//bookList=JUtil.simpleQuery(keyword,queryname,querymode);//这句话就不行了,查询结果为空,但是我输入的参数和上面一行是一样的,我用debug看过了,没有问题,
String isEmpty="false";
System.out.println("the BL is empty" bookList.isEmpty());
if(bookList.isEmpty()==true){
isEmpty="true";
}
request.setAttribute("bookList", bookList);
request.setAttribute("isEmpty", isEmpty);



return mapping.findForward("sqResult");
}
}
哪位兄才见过这种问题么?



网友回复:private String queryname ="";
private String querymode ="";
private String keyword="";
建议写成不用显示初始化
private String queryname;
private String querymode;
private String keyword;


确认此处的参数值已经传递过来????
String keyword=sqForm.getKeyword();
String querymode=sqForm.getQuerymode();
String queryname=sqForm.getQueryname();
网友回复:原来问题发生在sql里,现在问题已经解决了,谢谢
关键字:ActionForm,取得,String,不能,传到,一个,

文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面