我在 tomcat 中使用基于表单的身份验证,实际上我使用的是 j_security_check。代码如下
<form method="POST" action="j_security_check">
<table>
<tr>
<td colspan="2">Login to the Tomcat-Demo application:</td>
</tr>
<tr>
<td>Name:</td>
<td><input type="text" name="j_username" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="j_password"/ ></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Go" /></td>
</tr>
</table>
</form>
我想使用已在报告中登录的用户。我想从 session 中捕获登录的用户。我的想法是使用下面的jsp语法来设置变量
<%
session.setAttribute("myName",request.getParameter("user"));
%>
但是,我不确定如何像这样设置 session 变量,因为在身份验证后不久,它就会被重定向到请求的 URL
谁能帮忙
问候 阿里夫
最佳答案
通常通过过滤器解决。 检查 tomcat 文档中的过滤器,并应用你的过滤器(可能匹配每个请求,因为你不能应用它。谷歌搜索关键字 session、filter、principal。
dofilter() {
getSession;
if(session->user is not set) {
session->user = request->getPrincipal->getUsername() //something like that
}
}
关于jsp - 生/tomcat : set session variable after j_security_check,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24407091/