Java Servlet与认证 [英] Java servlet and authentication

查看:156
本文介绍了Java Servlet与认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3-4个servlet的一个小应用程序和基础模块提供me认证,如:

I have a small application with 3-4 servlets and a basic module that provide me authentication like:

public class Authentication {
    public boolean isUserAuthenticated(){
	    ....
    }
}

有没有办法用我的班级每一个其他servlet调用之前检查验证,而不需要添加code在他们每个人的?我想,以避免用户为每一个的servlet我和每一个servlet的,我将要补充的检查。

Is there a way to check the authentication using my class BEFORE every other servlet calls, without have to add code in each of them? I'd like to avoid the check of the user for every servlet I have and for every servlet I will have to add.

任何建议广为接受:)

谢谢,罗伯托

推荐答案

当然,使用 Servlet过滤器。它在Java Web应用程序中实现安全性的标准方法。

Absolutely, use a servlet filter. It's the standard way of implementing security in Java Web applications.

Java Servlet规范版本
  2.3引入了一个新的组件类型,称为过滤器。过滤器动态
  拦截请求,并响应
  变换或使用该信息
  包含在请求或
  响应。过滤器通常不
  自己创造的反应,但
  而不是提供普遍的功能
  可附加的任何类型的
  servlet或JSP页面。

The Java Servlet specification version 2.3 introduces a new component type, called a filter. A filter dynamically intercepts requests and responses to transform or use the information contained in the requests or responses. Filters typically do not themselves create responses, but instead provide universal functions that can be "attached" to any type of servlet or JSP page.

这篇关于Java Servlet与认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆