public class servletclass extends HttpServlet{
       int count;
       public void init() throws ServletException{
         count=0;
       }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
     String url="result.jsp";
     request.setAttribute("count",String.valueOf(count));
getServletContext().getRequestDispatcher(url).dispatcher.forward(request,response);
    }
       ......
}在result.jsp中,
<%
String count=request.getAttibute("count");
int count=Integer.parseInt(count);
%>

解决方案 »

  1.   

    在result.jsp中,
    <%
    String count=(String)request.getAttibute("count");
    int count=Integer.parseInt(count);
    %>不好意思!
      

  2.   

    Session.setAttribute()Session.getAttribute()
      

  3.   

    To zhangbin_zhang(cat):
       你的代码完成的功能是servlet处理任一次请求时都把count值传给result.jsp吧?
       这里面有两个问题:
       1.我希望的功能是由result.jsp主动读取count值;
       2.getServletContext().getRequestDispatcher("result.jsp").dispatcher.forward(request,response);会不会导致页面专向result.jsp?这不是我希望的