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

  • Home
  • SEARCH
  • 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 8615327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:21:01+00:00 2026-06-12T05:21:01+00:00

Using Struts 2, I have this interceptor: public class AccessInterceptor extends AbstractInterceptor { @Override

  • 0

Using Struts 2, I have this interceptor:

public class AccessInterceptor extends AbstractInterceptor {
    @Override
    public String intercept(ActionInvocation ai) throws Exception {
        ActionContext actionContext = ai.getInvocationContext();
        Map<String, Object> session = actionContext.getSession();
        Boolean logged = (Boolean) session.get("logged");
        if(logged == null) {
          session.put("logged", false);
          logged = false;
        }
        if (!logged) {
            // If exception is here, it IS thrown, so I am sure "login" is returned on /homepage
            return "login";
        }   
        return ai.invoke();
    }
}

And this struts.xml:

<?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>
<constant name="struts.devMode" value="true" />
<package name="loginInterceptor" namespace="/" extends="struts-default">
    <interceptors> 
        <interceptor name="access"
         class="logininterceptor.interceptors.AccessInterceptor"/>
        <interceptor-stack name="appDefault"> 
            <interceptor-ref name="access" />
            <interceptor-ref name="defaultStack" /> 
        </interceptor-stack> 
    </interceptors> 
    <default-interceptor-ref name="appDefault" />       
    <global-results>
        <result name="login">/WEB-INF/content/login.jsp</result>
    </global-results>
</package>
</struts>

I have also /WEB-INF/content/homepage.jsp JSP and /WEB-INF/content/login.jsp and mypackage.LoginAction.java class. There is not an acton class for homepage

The problem is, that when I go to the /homepage page, it is NOT redirected to login.jsp and I see the homepage.jsp content. What is wrong?

PS: I use struts2-convention-plugin

  • 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-12T05:21:03+00:00Added an answer on June 12, 2026 at 5:21 am

    This is happening because the conventions plugin uses the “convention-default” package which does not know about your interceptor or interceptor stack.

    If you could create a package which extends conventions-default doing just what your interceptor stack does (defines the interceptor, interceptor stack and defines the default result type) and then make the conventions plugin apply that stack as the default for all actions wouldn’t that be great? You can.

    After the <struts> tag define a constant like so:

    <constant name="struts.convention.default.parent.package" value="loginInterceptor"/>
    

    The other suggestion, was to use struts.xml to override the conventions, which is fine but a little verbose.

    Another option is to use the parent package annotation, which is good when you need to override the default behavior but as you pointed out you want this to be the default behavior so you should reserve annotations for overriding this, not to implement it.

    It may be worth browsing the following list of struts2 conventions plugin constants for the future: http://struts.apache.org/2.1.8/docs/convention-plugin.html#ConventionPlugin-Overwritingpluginclasses

    PS: Just naming preference but I would call your package login-package rather than loginInterceptor… not a big deal.

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

Sidebar

Related Questions

I'm using Struts 1. I have an Action, and when this Action forwards to
I have been using struts-errors to pass messages from dispatch action class to view
I have this struts code where I am using forEach- <c:forEach items=${reviewList} var=reviewListId> <tr>
I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a
I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a
I am using Struts 2. I have a JSP. It has this code: <span
I have this line of code in my JSP. (I'm using struts 1.3) <html:form
This is for a web application using struts. I have an array of objects
I have this very simple example that I am using to learn structs in
I have started using struts .I have hanged in a place ,Code is bellow

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.