这是我的servlet
,我已将lasti
发送到JSP
但它返回null
的Servlet
public void service(HttpServletRequest request,HttpServletResponse response)
{
PrintWriter out=null;
Connection con=null;
response.setContentType("text/html");
try
{
out=response.getWriter();//
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());//java.sql.*;
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","xweb","abc");
String query="select * from inbox";
System.out.println(query);
PreparedStatement pstmt=con.prepareStatement(query);
ResultSet rs=pstmt.executeQuery();
int i=0;
while(rs.next())
{
String str=rs.getString(2);
System.out.println(str);
i++;
request.setAttribute("k"+i,str);
}
request.setAttribute("lasti",i);
RequestDispatcher rd=request.getRequestDispatcher("inboxSuccess.jsp");
rd.forward(request,response);
} catch(Exception e)
{
try{
RequestDispatcher rd=request.getRequestDispatcher("customerLoginError.jsp");
rd.forward(request,response);
}catch(Exception e1){}
e.printStackTrace();
}
finally
{
try
{
con.close();
}catch(Exception e){}
}
}
JSP
<%
int x=(Integer)request.getAttribute("lasti");
out.println(x);
%>
返回0
当我在中使用 x 进行循环时,循环工作5次
但我无法打印 x 的值。
我是Java的新手,所以我不知道如何使用JSTL