Servlet不允许打开表单登录页面

时间:2018-10-19 12:25:14

标签: java url servlets weblogic web.xml

我有servlet与 @WebServlet({"/*", "/secure/*"}) 注解。第二个url是为可通过身份验证的用户获取的内容创建的。以及所有用户的第一个网址。

作为服务器,我正在使用weblogic。这就是我的web.xml

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Protected Area</web-resource-name>
        <url-pattern>/secure/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>authenticated</role-name>
    </auth-constraint>
</security-constraint>
<login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
        <form-login-page>/login.html</form-login-page>
        <form-error-page>/error.html</form-error-page>
    </form-login-config>
</login-config>
<security-role>
    <role-name>authenticated</role-name>
</security-role>

和weblogic.xml

<security-role-assignment>
    <role-name>authenticated</role-name>
    <principal-name>auth_user</principal-name>
</security-role-assignment>

因此,当我尝试请求localhost:7001/myservlet/secure?id=329时,我得到了localhost:7001/myservlet/login.html。而且是正确的。但是我没有得到我的login.html表格。我的servlet认为该URL适合他并尝试对其进行处理。而且我得到了错误。有什么想法可以解决这个问题吗?

P.S。当我从"/*"删除@WebServlet时,我会成功获得login.html表格。但是我无法更改servlet的网址。

更新

我删除了多余的代码并获得了该servlet代码

@WebServlet({"/*", "/secure/*"})
public class MyServlet extends HttpServlet {

protected void doGet(HttpServletRequest request, HttpServletResponse response) {

    ContentGetter getter = new ContentGetter();

        try (OutputStream os = response.getOutputStream();
                InputStream is = getter.getIsFromDB(request.getParameterMap())) {

            IOUtils.copy(is, os);

        } catch (IOException e) {
            logger.error("Object getting is failed. " + e.toString(), e);
            return;
        }
    }

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    doGet(request, response);
}
}

如果参数Map为空,则方法getter.getIsFromDB(request.getParameterMap()引发IllegalArgumentException。最后我得到错误500。

0 个答案:

没有答案