我有一个关于servlets和jsp的问题。从Servlet发送一个变量到JSP
的Servlet:
public class Servlet extends javax.servlet.http.HttpServlet {
protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
Integer i = new Integer(15);
request.setAttribute("var", i);
RequestDispatcher Dispatcher = getServletContext().getRequestDispatcher("/index.jsp");
Dispatcher.forward(request, response);
}
JSP页面:
<html>
<head>
<title></title>
</head>
<body>
<form id="id" method="get" action="servlet">
<%= (request.getAttribute("var")) %>
</form>
</body>
</html>
因此,我希望看到15,但我看空。为什么会发生?
固定它。结果是一样的:( –
同一个应用程序(WAR,项目...)中包含的servlet和JSP? –
是的,它的想法项目 –