猿问

新手学JAVA WEB问题

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 怎么获取显示到网页上

UYOU
浏览 341回答 1
1回答

一只斗牛犬

需要在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 {    }}
随时随地看视频慕课网APP

相关分类

Java
我要回答