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);
%>
上一篇: 验证码和七天免登陆