我在外部属性文件中提到了多个用户ID(例如:userId=ab123c,bf111y,…(。如果记录的用户的id与属性文件中提到的id匹配,我想用这个列表验证记录的用户,并允许访问某些jsp。当属性文件中只有一个userId时,我想好了如何验证。不知道如何与多个用户进行交互。我是开发和编码的新手,所以我请求你详细解释我需要做什么。
代码:
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String userAttuid = (String)myApp.properties.getProperty(“userId”);
String loggedUser = (String)request.getAttribute(“attuid”);
//I need help here to validate for multiple users
// I have written code for one user
If(loggedUser.equalsIgnoreCase(userAttuid) {
forwardToClient(“/Settings.jsp”,request,response);
}
else {
throw new exception();//any suitable exception
}
感谢您的帮助,提前感谢
您可以始终读取用户id,将其拆分并作为列表保存。请参阅下面的方法:
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String userAttUids = (String)myApp.properties.getProperty(“userId”);
// Split configured IDs to a list
List<String> userAttrIds = Arrays.asList(userAttUids.toLowerCase().split(","))
String loggedUser = (String)request.getAttribute(“attuid”);
//check if the user id is present in the list
if(userAttrIds.contains(loggedUser.toLowerCase())) {
forwardToClient(“/Settings.jsp”,request,response);
}
else {
throw new exception();//any suitable exception
}
}