*SOS***(Session in jsp and servelet)***SOS* INLINE

flyshp flyshp 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

这是我的jsp

<%
session.setAttribute("name","Hello");
String pass = (String)session.getAttribute("pass");

response.sendRedirect("../jspweb/servlet1");
System.out.println(pass);
%>

这是ejbpackage jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class Servlet1 extends HttpServlet {
static final private String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Servlet1</title></head>");
out.println("<body bgcolor=\"#ffffff\">");
HttpSession session=request.getSession ();
session.setAttribute("pass","12345") ;
out.println("name的值是:"+(String)session.getAttribute("name"));
out.println("<p>The servlet has received a GET. This is the reply.</p>");
out.println("</body></html>");
}
//Clean up resources
public void destroy() {
}
}


...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
flyshp
Web 开发 81,108 成员 341,721 内容