婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > JSP使用Servlet過濾器進行身份驗證的方法

JSP使用Servlet過濾器進行身份驗證的方法

熱門標簽:電銷機器人好賣么 高德地圖標注樣式 商洛電銷 電銷機器人是有一些什么技術(shù) 杭州語音電銷機器人軟件 杭州ai語音電銷機器人功能 地圖標注線上教程 四川保險智能外呼系統(tǒng)商家 北票市地圖標注

本文實例講述了JSP使用Servlet過濾器進行身份驗證的方法。分享給大家供大家參考,具體如下:

1、Servlet過濾器的作用描述

(1)在HttpServletRequest到達Servlet 之前,攔截客戶的HttpServletRequest。
根據(jù)需要檢查HttpServletRequest,也可以修改HttpServletRequest頭和數(shù)據(jù)。
(2)在HttpServletResponse 到達客戶端之前,攔截HttpServletResponse。
根據(jù)需要檢查HttpServletResponse,可以修改HttpServletResponse頭和數(shù)據(jù)。

2、應用Servlet過濾器進行身份驗證

假設網(wǎng)站根目錄下的login1.htm、longin1.jsp用于用戶登錄,而chap08目錄下的文件需要用戶登錄后才能訪問。

(1)編寫Servlet過濾器

@WebFilter("/FilterStation")
public class FilterStation extends HttpServlet implements Filter {
private FilterConfig filterConfig;
public FilterStation() {
super();
}
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpSession session=((HttpServletRequest)request).getSession();
response.setCharacterEncoding("gb2312");
if(session.getAttribute("me")==null){
PrintWriter out=response.getWriter();
out.print("script>alert('請登錄!');location.href='../login1.htm'/script>");
}
else{
// pass the request along the filter chain
chain.doFilter(request, response);
}
}
public void init(FilterConfig fConfig) throws ServletException {
// TODO Auto-generated method stub
this.filterConfig=fConfig;
}
}

(2)配置web.xml

filter>
filter-name>filterstation/filter-name>
filter-class>zhou.FilterStation/filter-class>
/filter>
filter-mapping>
filter-name>filterstation/filter-name>
url-pattern>/chap08/*/url-pattern>
/filter-mapping>

(3)login1.htm代碼

html>
head>
title>用戶登錄/title>
/head>
body>
form method="POST" action="login1.jsp">
p>用戶名:input type="text" name="user" size="18">/p>
p>密碼:input type="text" name="pass" size="20">/p>
p>input type="submit" value="提交" name="ok">
input type="reset" value="重置" name="cancel">/p>
/form>
/body>
/html>

(4)login1.jsp代碼

%@ page contentType="text/html;charset=GB2312" %>
html>
head>title>Session 應用演示/title>/head>
% 
if (request.getParameter("user")!=null  request.getParameter("pass")!=null)
{
String strName=request.getParameter("user");
String strPass=request.getParameter("pass");
if (strName.equals("admin")  strPass.equals("admin"))
{
session.setAttribute("login","OK");
session.setAttribute("me",strName);
response.sendRedirect("chap08/welcome.jsp");
}
else
{
out.print("script>alert('用戶名或密碼錯誤');location.href='login1.htm'/script>");
}
}
%>
/html>

希望本文所述對大家JSP程序設計有所幫助。

您可能感興趣的文章:
  • 通過過濾器(Filter)解決JSP的Post和Request中文亂碼問題
  • JSP過濾器Filter配置過濾類型全部匯總
  • JSP 開發(fā)中過濾器filter設置編碼格式的實現(xiàn)方法
  • JSP過濾器防止Xss漏洞的實現(xiàn)方法(分享)
  • JSP使用過濾器防止SQL注入的簡單實現(xiàn)
  • jsp實現(xiàn)登錄驗證的過濾器
  • jsp中過濾器選擇過濾器的寫法詳解
  • 詳解JSP中使用過濾器進行內(nèi)容編碼的解決辦法
  • servlet+jsp實現(xiàn)過濾器 防止用戶未登錄訪問
  • JSP使用過濾器防止Xss漏洞
  • jsp filter 過濾器功能與簡單用法示例

標簽:云浮 紅河 江西 丹東 宿州 青島 西藏 貴州

巨人網(wǎng)絡通訊聲明:本文標題《JSP使用Servlet過濾器進行身份驗證的方法》,本文關(guān)鍵詞  JSP,使用,Servlet,過濾器,進行,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《JSP使用Servlet過濾器進行身份驗證的方法》相關(guān)的同類信息!
  • 本頁收集關(guān)于JSP使用Servlet過濾器進行身份驗證的方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 柯坪县| 黔西县| 贡觉县| 灵石县| 东丰县| 中山市| 拜城县| 民权县| 阳信县| 孝昌县| 蛟河市| 泽普县| 林周县| 津南区| 武冈市| 江山市| 慈利县| 嘉义市| 城市| 射洪县| 上蔡县| 安康市| 宁波市| 牙克石市| 锦屏县| 汉源县| 彭泽县| 通许县| 北宁市| 麦盖提县| 牡丹江市| 清原| 苍梧县| 鸡西市| 固镇县| 堆龙德庆县| 贵州省| 兴海县| 托克逊县| 沅陵县| 武汉市|