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 8779475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:47:48+00:00 2026-06-13T19:47:48+00:00

I have a small application to learn Struts2 Application I write a admin page

  • 0

I have a small application to learn Struts2 Application

I write a admin page and inside that , my code will check if user logged or not, if not it will redirect to login page.

I write interceptor to check for all pages that user try to access but not login, it will redirect this user to login page. Everything is work well, but when i enter username and password correct with database, it can not login, when i remove interceptor i can be logged into admin page

Cause maybe interceptor check session of user before and after login, but maybe some cases i dont know why my application, session get null althought my username and password is true but it till null when i set session.

My code bellow will show you what i said:

Login Action

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.dejavu.software.view;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.Map;
import org.apache.struts2.interceptor.SessionAware;
import org.dejavu.software.dao.UserDAO;
import org.dejavu.software.model.GroupMember;
import org.dejavu.software.model.User;

/**
 *
 * @author Administrator
 */
public class AdminLoginAction extends ActionSupport {

    private static final long serialVersionUID = -1457633455929689099L;
    private User user;
    private String username, password;
    private String role;
    private UserDAO userDAO;
    private GroupMember group;    

    public AdminLoginAction() {
        userDAO = new UserDAO();

    }

    @Override
    public String execute() {
        String result = null;
        System.out.println(getUsername());
        if (getUsername().length() != 0 && getPassword().length() != 0) {
            setUser(userDAO.checkUsernamePassword(getUsername(), getPassword()));            
            if (getUser() != null) {
                for (GroupMember g : getUser().getGroups()) {
                    boolean admincp = g.getAdminpermission().contains("1");
                    if (admincp == true) {
                        Map session = ActionContext.getContext().getSession();  
                        session.put("userLogged", getUsername());
                        session.put("passwordLogged", getPassword());
                        result = "success";
                    } else {
                        result = "error";
                    }
                }

            }
        }        
        return result;
    }

    @Override
    public void validate() {
        if (getUsername().length() == 0) {
            addFieldError("username", "Username is required");
        }
        if (getPassword().length() == 0) {
            addFieldError("password", getText("Password is required"));
        }

    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public GroupMember getGroup() {
        return group;
    }

    public void setGroup(GroupMember group) {
        this.group = group;
    }


}

My custom interceptor Code:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.dejavu.software.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import java.util.Map;
import org.apache.struts2.StrutsStatics;

/**
 *
 * @author Anministrator
 */
public class LoginInterceptor extends AbstractInterceptor implements StrutsStatics {

    private static final long serialVersionUID = -3874262922233957387L;

    @Override
    public void destroy() {
    }

    @Override
    public void init() {
    }

    @Override
    public String intercept(ActionInvocation ai) throws Exception {
        Map<String, Object> session = ai.getInvocationContext().getSession();
        Object user = session.get("userLogged");

        if (user == null) {
            return "login";
        } else {
            return ai.invoke();
        }
    }
}

my struts config

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

    <package name="default" namespace="/" extends="struts-default">
        <action name="index" class="org.dejavu.software.view.HomeAction">
            <result>home.jsp</result>
        </action>
        <action name="about" class="org.dejavu.software.view.AboutHomeAction">
            <result>about.jsp</result>
        </action>
    </package>  

    <package name="admincp" namespace="/admincp" extends="struts-default">
        <interceptors>
            <interceptor name="login" class="org.dejavu.software.interceptor.LoginInterceptor" />
            <interceptor-stack name="stack-with-login">
                <interceptor-ref name="login"/>
                <interceptor-ref name="defaultStack"/>
            </interceptor-stack>
        </interceptors>
        <default-interceptor-ref name="stack-with-login"/>

        <global-results>
            <result name="login">login.jsp</result>
        </global-results>

        <action name="logincp" class="org.dejavu.software.view.AdminLoginAction">
            <result name="success">dashboard.jsp</result>
            <result name="input">login.jsp</result>
            <result name="error">login.jsp</result>
        </action>

    </package>  

</struts>

When i enter correct username and password match to database it till redirect to login.jsp page

and i have no idea about that

please help me

Thank you very much

  • 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-13T19:47:49+00:00Added an answer on June 13, 2026 at 7:47 pm

    You must configure your login action to use default interceptor stack or it will NOT execute your method because your interceptor will return login result.

    <action name="logincp" class="org.dejavu.software.view.AdminLoginAction">
      <interceptor-ref name="defaultStack" />
      <result name="success">dashboard.jsp</result>
      <result name="input">login.jsp</result>
      <result name="error">login.jsp</result>
    </action>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Work on this small test application to learn threading/locking. I have the following code,
I have this small application that I'm building as an exercise to learn the
I have a small application that uses WCF to communicate with a webserver. This
I have a small application that I am building a Chat application into, so
I have a small application that uses a SharePoint list as the data source.
I have a small application that redirects the stdout/in of an another app (usually
I have a small application which embeds webbrowser controls. In that application I have
I have been task with (ha) creating an application that will allow the users
I have a small web application based on asp.net 2010 that manages invoices. After
I have a small application that I was running right now and I wanted

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.