欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

servlet用session传int类型值到jsp页面

程序员文章站 2024-03-20 12:42:40
...
Servlet:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

HttpSession session=request.getSession();


int id=Integer.parseInt(request.getParameter("id"));
session.setAttribute("id", id+"");//隐式把int转String
request.getRequestDispatcher("an.jsp").forward(request, response);
}

jsp:

<%
	int id=Integer.parseInt((String)session.getAttribute("id"));//接受从控制器上设置好的id值,把String转化为int
	out.print(id);
	
 %>