我在映射到我的 servlet 的浏览器链接中打开,并希望显示传递的值。但我看到的是“空”
小服务程序:
public class TestServlet extends HttpServlet {
public TestServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setAttribute("var", "a");
request.getRequestDispatcher("index.jsp").forward(request, response);
}
}
jsp:
<%
String s1 = (String) session.getAttribute("var");
%>
<%= s1 %>