我已经在 servlet 上测试了一个简单的测试。我想向 JSP 显示我在 servlet 中所做的值,但它似乎没有出现。这是我的代码。
测试.java(servlet):
public class Test extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Test() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String message = "hello";
request.setAttribute("message", message);
request.getRequestDispatcher("/servlet-test.jsp").forward(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
servlet-test.jsp(页面):
<p>Message: ${message}</p>
web.xml
<servlet>
<description></description>
<display-name>Test</display-name>
<servlet-name>Test</servlet-name>
<servlet-class>com.fluxion.mrcos.actions.Test</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/Test</url-pattern>
</servlet-mapping>
然后,当我要在页面中查看它时,该值不会出现。哪天能告诉我怎么了?