Servlet方法

本文详细介绍了在Java Web开发中,ServletRequest、ServletResponse和FilterChain的角色。通过示例展示了如何获取请求信息,如工程名、页面路径、URL和URI,并解释了HttpServletResponse的重定向方法。同时,还提到了HttpSession的使用,如设置属性。这些内容对于理解和操作HTTP请求响应及会话管理至关重要。
摘要由CSDN通过智能技术生成

ServletRequest

ServletResponse

FilterChain

跳转到拦截的路径:chain.doFilter(request, response)


以访问的jsp为:http://localhost:8080/dmsd-itoo-exam-log-web/course/index.jsp,工程名为/dmsd-itoo-exam-log-web为例:HttpServletRequest

        request.getContextPath(),得到工程名:/dmsd-itoo-exam-log-web;

        request.getServletPath(),返回当前页面所在目录下全名称:/course/index.jsp;

        request.getRequestURL(),返回IE地址栏地址:http://localhost:8080/dmsd-itoo-exam-log-web/course/index.jsp;

        request.getRequestURI() ,返回包含工程名的当前页面全路径:/dmsd-itoo-exam-log-web/course/index.jsp。

HttpServletResponse

重定向跳转controller相同的请求中:response.sendRedirect("路径")

HttpSession

session.setAttribute("键","值")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值