Java基础之HttpServletRequest请求(2)

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //向request域中存值
        request.setAttribute("name", "张三" );
        //请求转发
        request.getRequestDispatcher("/Servlet02").forward(request, response);
   
       
    }

public class Servlet02 extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //从request 域中取值
        String name =(String)request.getAttribute("name");
        //解决中文乱码
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write("hello"+name);
    }

Linux公社的RSS地址https://www.linuxidc.com/rssFeed.aspx

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/f1cd6d6091f7d1dae31a955043365794.html