我做一个jsp时,当点击菜单连接时,先从数据库中查出生日等于当天的记录
代码如下:
  <% String sqlText="select * from customer where birthday=getdate()";
     ResultSet rs=UtilBean.executeQuery(sqlText);
     while(rs.next()){
         out.println("<tr>");
         out.println("<td>"+rs.getString("custNo")+"</td>");
       ....
}
在显示完所有数据后,还需要在下面有一个select供用户选择,当天,未来7天,的客户生日名单
当选择完后,再点击右边的查询,则查询.
<select name="day">
 <option value="1">当天</option>
 <option value="2">未来7天</option>
这样需要用request.getParameter("day")
当用  String s=request.getParameter("day")
 if(s.equals("1")
   strWhere="getdate()";
else if(s.equasl("2"))
   strWhere="getdate()+7"  //
String ss="select * from customer where birthday<="+strWhere
executeQuery();
当执行到时,s总是null值,原因是一打开窗体时就执行了查询,当点击提交时,得不到正确结果,有人告诉我,需要设置一个变量,起初为null,只有点击提交后,才不为null,
不为null才执行后面的程序.
请问好心人,是如何设置的?
  

解决方案 »

  1.   

    request.getParameter("day")
    你有过request.setParameter("day","");没
    如果没有set当然就get不出来``
    你这里当天还是一星期,应该是select选择的,不是从request中得到的
    应该从select得到
      

  2.   

    To:caichongbo(橘子) ( ) 信誉:100    Blog 
    有request.setParameter()吗?
    详情请参见:
     
      在什么时候用request.getAttribute?
    何时用request.getParameter呢?一直不是很清楚这个尤其是Parameter
    是不是除了标单提交后的取值用到外,就再也没用了?
     
     
     这个问题问得很好。
    HttpServletRequest类既有getAttribute()方法,也由getParameter()方法,这两个方法有以下区别:(1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法(2)当两个Web组件之间为链接关系时,被链接的组件通过getParameter()方法来获得请求参数,例如假定welcome.jsp和authenticate.jsp之间为链接关系,welcome.jsp中有以下代码:<a href="authenticate.jsp?username=weiqin">authenticate.jsp </a>或者:<form name="form1" method="post" action="authenticate.jsp">
      请输入用户姓名:<input type="text" name="username">
      <input type="submit" name="Submit" value="提交">
    </form>在authenticate.jsp中通过request.getParameter("username")方法来获得请求参数username:<% String username=request.getParameter("username"); %>(3)当两个Web组件之间为转发关系时,转发目标组件通过getAttribute()方法来和转发源组件共享request范围内的数据。假定authenticate.jsp和hello.jsp之间为转发关系。authenticate.jsp希望向hello.jsp传递当前的用户名字,如何传递这一数据呢?先在authenticate.jsp中调用setAttribute()方法:<%
    String username=request.getParameter("username");
    request.setAttribute("username",username);
    %><jsp:forward page="hello.jsp" />在hello.jsp中通过getAttribute()方法获得用户名字:<% String username=(String)request.getAttribute("username"); %>
    Hello: <%=username %> 
    -----------------------------------------------------------------
    如果你在这个论坛得到了有益的帮助,也请给别人提供帮助,我相信,爱心是可以传递的,一定会的!  
    http://www.javathinker.org/bbs/topic.jsp?db=2&topic=76
      

  3.   

    String s="";
    if(request.getParameter("day")!=null&&!request.getParameter("day").equals(""))
    {
    s=request.getParameter("day");
    }