首页 > 学院 > 开发设计 > 正文

HttpServletRequest和ServletRequest的区别

2019-11-11 06:19:17
字体:
来源:转载
供稿:网友
HttpServletRequest和ServletRequest都是接口

HttpServletRequest继承自ServletRequest 

HttpServletRequest比ServletRequest多了一些针对于Http协议的方法。 例如:

getHeader(), getMethod() , getsession() 

	@Override	public void doFilter(ServletRequest request, ServletResponse response,			FilterChain filterChain) throws IOException, ServletException {		// 过滤用户请求,判断是否登录		HttpServletRequest httpServletRequest = (HttpServletRequest)request;		HttpServletResponse httpServletResponse = (HttpServletResponse)response;		httpServletResponse .setContentType("text/html;charset=utf-8");		httpServletRequest.setCharacterEncoding("utf-8");		httpServletResponse.setCharacterEncoding("utf-8");				String username = (String)httpServletRequest.getSession().getAttribute("username");		if (username == null) {			String path = httpServletRequest.getContextPath();			httpServletResponse.sendRedirect(path+"/index.jsp");		}		filterChain.doFilter(httpServletRequest, httpServletResponse);	}


上一篇:qt protobuf使用

下一篇:Spring创建单例bean

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表