首先,我在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">
<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的语句又看不到结果了,请问高手,这是为什么啊?
.......
<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">
<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的语句又看不到结果了,请问高手,这是为什么啊?
我的SQL语句是返回唯一的结果了,没有错才对啊
request.setAttribute("ntitle", ntitle);
request.setAttribute("nimages", nimages);
request.setAttribute("nwirter", nwirter);
request.setAttribute("ndate", ndate);
request.setAttribute("ncontent", ncontent);
为何你不这样写呢
<%=(String)request.getAttribute("ncontent") %>
想把最后一跳放到request里面直接把指针指到rs的最后一行设置一下就可以了,还可以提高性能
后面的仁兄我也测试过了
数组也不可以,arraylist方法也不可以.揪心吧.