public class AllServlet extends HttpServlet { String title = "title..."; private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.getRequestDispatcher("/themes/tuzuan/all.jsp").forward(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { }}这个 title 在 all.jsp 怎么获取显示到网页上
1 回答
一只斗牛犬
TA贡献1784条经验 获得超2个赞
需要在request中设置相应的属性才能在页面接收到
public class AllServlet extends HttpServlet {
String title = "title...";
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setAttribute("title", title);
request.getRequestDispatcher("/themes/tuzuan/all.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
添加回答
举报
0/150
提交
取消