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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:27:14+00:00 2026-05-24T04:27:14+00:00

I’m writting custom handler interceptor in order to have multilangual url addresses. For example,

  • 0

I’m writting custom handler interceptor in order to have multilangual url addresses. For example, when user accesses uri /de/auto the deutsch content will appear, when user accesses /en/car then english content will appear. I want both requests redirect to same controller and same method:

@Controller
public class MultiLangController {

    @RequestMapping(value="/en/car", method = RequestMethod.GET)
    public @ResponseBody String writePage() {

        return "some content";
    }

and my interceptor is implemented like this (simplified version):

public class MultiLangInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request,
    HttpServletResponse response, Object handler) throws Exception {

        String requestUrl = request.getRequestURI().substring(request.getContextPath().length());

        if ("/de/auto".equals(requestUrl)) {
            String redirect = request.getContextPath() + "/en/car";

            response.sendRedirect(redirect);
            return false;
        }
        return true;        
    }
}

Now when I access /en/car url in browser, correct page is returned (with message “some content”) and logs shows that request passed through my interceptor. When I access /de/auto, 404 error is returned and according to logs request didn’t make it to my interceptor. But why? Shouldn’t request go through all interceptors till one of them stops it by returning false?

For clarity, I’m not using mvc:annotation-driven because it was hidding my custom interceptor. I’ve defined all manualy

<bean id="handlerMapping"
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    <property name="interceptors">
        <ref bean="multiLangInterceptor" />
    </property>
</bean>

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
        <list>
            <ref bean="jacksonMessageConverter"/>
            <ref bean="stringHttpMessageConverter"/>
        </list>
    </property>
</bean>

<bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>

<bean id="multiLangInterceptor" class="example.MultiLangInterceptor" />    

<bean id="stringHttpMessageConverter" 
    class="org.springframework.http.converter.StringHttpMessageConverter"/> 

Thanks for answers!

  • 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-05-24T04:27:15+00:00Added an answer on May 24, 2026 at 4:27 am

    It can’t really send every single incoming request to the interceptors before determining if there’s a mapping. Notice that one of the arguments to the interceptor is the Controller itself! If the URL that’s coming in is one that’s not mapped anywhere, how is it supposed to know what handler that would be to pass in as a method argument? URL rewriting needs to be done further up the stack, before the request hits the dispatcher servlet. E.G., in a servlet filter for that purpose.

    Another possible option is to map your Controller this way

    @RequestMapping(value="/{languageCode}/car", method = RequestMethod.GET)
    

    As long as you don’t have other mappings of /something/car in the same dispatcher that will collide.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from

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.