Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8308921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:57:02+00:00 2026-06-08T18:57:02+00:00

I want to implement form based authentication in struts2. My directory structure is :

  • 0

I want to implement form based authentication in struts2.

My directory structure is :

enter image description here

My web.xml:

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <security-constraint>
        <display-name>Example Security Constraint</display-name>
        <web-resource-collection>
            <web-resource-name>Protected Area</web-resource-name>
            <url-pattern>/protected/*</url-pattern>
            <http-method>DELETE</http-method>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
            <http-method>PUT</http-method>
        </web-resource-collection>
        <auth-constraint>
            <role-name>manager</role-name>
        </auth-constraint>
        <user-data-constraint>
            <transport-guarantee>NONE</transport-guarantee>
        </user-data-constraint>
    </security-constraint>


    <!-- Default login configuration uses form-based authentication -->
    <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>Example Form-Based Authentication Area</realm-name>
        <form-login-config>
            <form-login-page>/login.jsp</form-login-page>
            <form-error-page>/error.jsp</form-error-page>
        </form-login-config>
    </login-config>
    <security-role>
        <description> An administrator </description>
        <role-name>
            manager
        </role-name>
    </security-role>

    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

my login.jsp :

<form method="POST" action="j_security_check" >
  <table border="0" cellspacing="5">
    <tr>
      <th align="right">Username:</th>
      <td align="left"><input type="text" name="j_username"></td>
    </tr>
    <tr>
      <th align="right">Password:</th>
      <td align="left"><input type="password" name="j_password"></td>
    </tr>
    <tr>
      <td align="right"><input type="submit" value="Log In"></td>
      <td align="left"><input type="reset"></td>
    </tr>
  </table>
</form>

action in struts :

<action name= "j_security_check" class="action.LoginAction" >
            <result name="success" >protected/index.jsp</result>
            <result name="error" > error.jsp </result>
            <result name="input" > login.jsp</result>
        </action>

my LoginAction.java

    public class LoginAction extends ActionSupport {

        String j_username, j_password;

        public String getJ_password() {
            return j_password;
        }

        public void setJ_password(String j_password) {
            this.j_password = j_password;
        }

        public String getJ_username() {
            return j_username;
        }

        public void setJ_username(String j_username) {
            this.j_username = j_username;
        }

        @Override
        public String execute() throws Exception {
            if (getJ_username().equals(getJ_password())) {
                return SUCCESS;
            } else {
                this.addActionError("Error..!");
                return ERROR;
            }
        }
@Override
    public void validate() {
        if ((getJ_username() == null) || (getJ_username().length() == 0)) {
            this.addActionError("Username Empty");
        }
        if ((getJ_password() == null) || (getJ_password().length() == 0)) {
            this.addActionError("Password Empty");
        }
    }

With this i am When i insert same loginid and password, yet i redirected to the error page..

Can someone give a good link for the same..?

The example should contain a protected folder, an action class for login..

thanks..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:57:04+00:00Added an answer on June 8, 2026 at 6:57 pm

    You will have to provide username and password combination that corresponds to a user who has already been created in the file realm of the GlassFish Server and has been assigned to the group of manager.

    Here is a link on how to create a File realm.

    Here is a link on how to create a jdbc security realm.

    Here is a working example. You can check if it matches with your code.

    Here is a link to better understand form-based authentication.

    Hope this helps. 🙂

    EDIT:

    The idea behind form based authentication is that you write a JSP or Servlet that presents a form with the following fields and action:

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

    When the form is submitted, the servlet container checks the credentials for you using the mechanism you’ve defined (e.g. JAAS). In your web.xml, you set the following:

    <login-config>
        <form-login-check>
            <form-login-page>/login.jsp</form-login-page>
            <form-error-page>/error.jsp</form-error-page>
        </form-login-check>
    </login-config>
    

    This allows the container to locate the JSP or Servlet containing your form, or your error handling code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement OpenID authentication in a simple JSP app. The FORM -based
I'm trying to implement a simple form-based login for my web application deployed with
If I want to create a customized ASP.Net MVC3 form based authentication, what are
I want to implement a simple help form to appear once the application has
i want to implement a sort of feedback form/survey form in asp.net which is
I want to implement the most secure, and most reliable form of symmetric key
In Django admin I want to override and implement my own form for a
I want to understand form based security and JDBC realms with glassfishV3, so i
I am trying to implement a browser based chat system with jQuery. I want
I want to implement some form of (GWT 2.1 MVP) pre-Activity checking that ensures

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.