Login to web form in Java

How to block access to the site if the user is not registered?

In the web.xml> Security file, I checked for form based authentication and then I selected the login and error page, but I don't know how to block access and redirect the user to the login page.

Do I need a filter? If so, how can I get the specified login url?

What can I call the verification method? I saw in some examples this code

    <form method=post action="j_security_check">
     <input type="text" name="j_username" />
     <input type="password" name="j_password" />
    </form>

      

What is he doing?

+2


a source to share


1 answer


To prevent people who are not logged in from viewing resources, you are using security restrictions. Something like that:



<security-constraint>
    <display-name>Constraint</display-name>
    <web-resource-collection>
        <web-resource-name>all-resources</web-resource-name>
        <description/>
        <url-pattern>/pages/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <description/>
        <role-name>User</role-name>
    </auth-constraint>
</security-constraint>

      

+3


a source







All Articles