要不要cookies支持?
session一般是servlet生成、管理...

解决方案 »

  1.   

    <%@ page contentType="text/html; charset=GBK" %>
    <%@ page session="true"%>
    <html>
    <head>
    <title>
    Jsp1
    </title>
    </head><body>
    <h1>
    Generated JSPgdfg
    </h1>
    <form  method="get" action="http://localhost:8080/servlet/untitled4.Servlet1" >
    <br>Enter new value   :  <input name="sample"><br>
    <br><br>
    <%
      session.setAttribute("name","test1");
    %>
    <input type="submit" name="Submit" value="Submit">
    <input type="reset" value="Reset">
    <br>
    Value of Bean property is :
    </form>
    </body>
    </html>
    --------------------------------------------------------------------------------
     public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType(CONTENT_TYPE);
        HttpSession session = request.getSession(true);
        PrintWriter out = response.getWriter();
        String bb = (String)session.getAttribute("name");
        out.println("<html>");
        out.println("<head><title>Servlet1</title></head>");
        out.println("<body>");
        out.println("name is:"+bb);
        out.println("<p>The servlet has received a GET. This is the reply.</p>");
        out.println("</body></html>");
      }
    我用的是tomcat,运行结果是null.