web应用中的路径问题

来源:互联网 发布:知乎 清华法学院体验 编辑:程序博客网 时间:2024/05/18 16:37
/** * web应用中路径问题 * @author Carl_Hugo * */public class PathDemo extends HttpServlet {    public void doGet(HttpServletRequest request, HttpServletResponse response)            throws ServletException, IOException {        response.setContentType("text/html;charset=utf-8");        //目标资源: target.html        /**         * 思考: 目标资源是给谁使用的。         *      给服务器使用的(request):   / 表示在当前web应用的根目录(webRoot下)         *      给浏览器使用的(response): /  表示在webapps的根目录下         */        /**         * 1.转发         */        request.getRequestDispatcher("/target.html").forward(request, response);        /**         * 2.请求重定向         */        response.sendRedirect("/day11/target.html");        /**         * 3.html页面的超连接href         */        response.getWriter().write("<html><body><a href='/day11/target.html'>超链接</a></body></html>");        /**         * 4.html页面中的form提交地址         */        response.getWriter().write("<html><body><form action='/day11/target.html'><input type='submit'/></form></body></html>");    }}
0 0
原创粉丝点击