手生就要多练啊。。。
package com.jeelearning.servlet; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; @WebServlet("/newSession") public class NewSession extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setCharacterEncoding("utf-8"); response.setHeader("Content-type", "text/html;charset=utf-8"); PrintWriter out = response.getWriter(); out.println("测试Session属性<br/><br/>"); HttpSession session = request.getSession(); if (session.isNew()) { out.println("新朋友<br/><br/>"); } else { out.println("欢迎回来<br/><br/>"); } } }