首先,我在main.jsp中用隐式的INPUT来传送一个数据库的唯一属性给我的Servlet,如下:
.......
<form action="WenServlet" method="POST">
<input type="hidden" name="id_c" value="<%=strid_c%>">
<tr> <td><img src="images/admin/arrow.gif" width="13" height="17">&nbsp;
<a  target="_bank"  onClick="JScript:submit();"style="cursor:hand;  color:#000000;"><%=strTitle%></a></td></tr></form>
....在我的Servlet中经过如下处理
....
public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
ConnBean db = new ConnBean();
String stridt =(String)request.getParameter("id_c");
String sql="select * from news where ntype='嘉西亚文化'and nid='"+stridt+"'";
try{
  ResultSet rst = db.getRs(sql); 
  String ncontent;
  String ndate ;
  String nwirter;
  String nimages;
  String ntitle; while(rst.next()){

ncontent = rst.getString(6);
ndate = rst.getString(4);
nwirter = rst.getString(5);
nimages = rst.getString(7);
ntitle =rst.getString(3);
request.setAttribute("ntitle", ntitle);
request.setAttribute("nimages", nimages);
request.setAttribute("nwirter", nwirter);
request.setAttribute("ndate", ndate);   
request.setAttribute("ncontent", ncontent);
}

ServletContext Scontext = getServletContext();
RequestDispatcher rd = Scontext.getRequestDispatcher("/new/test.jsp"); 
rd.forward(request, response);
....test.jsp页面如下
<%=request.getAttribute("ncontent") %>
<%=request.getAttribute("nimages") %>
<%=request.getAttribute("nwirter") %>
...我先想说一下,首先可以告诉大家,我的SQL语句可以在JSP页面上出现结果,不过最奇怪的是,我在上面用了很多条request.setAttribute("Object", String);我要是用一条这样的语句的话,就一定能看到结果,可是我要是用2条以上,那么就绝对在JSP上面看不到结果,我可以用任意一条都可以看到结果,可是我用2条request的语句又看不到结果了,请问高手,这是为什么啊?

解决方案 »

  1.   

    当然看不到,有个while(rs.next())呢
      

  2.   

    有个while(rst.next())很正常啊,把rst的结果取出来啊.
    我的SQL语句是返回唯一的结果了,没有错才对啊
      

  3.   

    把这些语句写到while(rs.next()) 循环外面去,应该就可以了
                               request.setAttribute("ntitle", ntitle);
    request.setAttribute("nimages", nimages);
    request.setAttribute("nwirter", nwirter);
    request.setAttribute("ndate", ndate);   
    request.setAttribute("ncontent", ncontent);
      

  4.   

    我觉得没有问题,
    为何你不这样写呢
    <%=(String)request.getAttribute("ncontent") %>
      

  5.   

    不可以啊,大佬,还是一样的,不可以多个request的方法啊....
      

  6.   

    以上的方法我都试过了,还是不可以,不过只用一个request的方法就可以,我靠,什么鬼问题.
      

  7.   

    rst.next()在这也没什么作用啊
    想把最后一跳放到request里面直接把指针指到rs的最后一行设置一下就可以了,还可以提高性能
      

  8.   

    呵呵,实在不行就传一个String数组好了。
      

  9.   

    恩,的确性能可以提高
    后面的仁兄我也测试过了
    数组也不可以,arraylist方法也不可以.揪心吧.