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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:59:38+00:00 2026-05-13T07:59:38+00:00

The problem I am trying to solve is that I want to check all

  • 0

The problem I am trying to solve is that I want to check all incoming GET urls against a database. If the the url exist in the database it shall be passed to a certein controller. I’m using Spring 3.0.

First I tried to make an interceptor and add that to DefaultAnnotationsHandlerMapping. Turns out i couldn’t modify the url in preHandle(). The plan was to modify the url in the request and then let an annotated controller handle the rest.

Next I tried to make a custom HandleMapping. I extended AbstractUrlHandlerMapping and made my own getHandlerInternal() that returns a String with the name of the Controller and this is working. But I’d prefer a solution where I can modify the url in the request and let an annotated controller handle it.

While writing this I got thinking that maybe a servlet filter is the most proper solution. If that’s the case can I get Spring to inject an EntityManager into the filter? Any Spring class I can extend that makes this easier?

What’s the most proper way to solve the problem in the first paragraph? If it’s the servlet filter please give me some pointers on how to write it.

  • 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-13T07:59:39+00:00Added an answer on May 13, 2026 at 7:59 am

    As has been pointed out by others, a standard servlet filter would do the job, but it’s not a very spring-friendly solution – the filter is not managed by Spring, and so cannot be wired with Spring beans. The filter would need to fetch the spring beans programmatically, which isn’t nice.

    The trouble with modifying the URL of an existing request is that it rather breaks the servlet API model. HttpServletRequest has multiple path- and URL-related methods that extract different parts of the original URL, and you’d have to make sure you somehow modified all of those values. The API just isn’t designed for that, whether you use filters or interceptors.

    SO rather than trying to subvert the API, my suggestion is you write a Spring controller that accepts the “old” path, and which forwards the request to the “new” path, based on the injected EntityManager. The forwarding can happen by having the controller handler method return a InternalResourceView with the “new” path. It’s not strictly speaking a view you’re forwarding to, but Spring won’t know the difference. Alternatively, you can forward it directly using request.getRequestDispatcher(newPath).forward(request, response).

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

Sidebar

Related Questions

I'm trying to solve a problem that anonymous functions make much, much easier, and
I'm trying to solve the following problem in Redis. I have a list that
This the problem in my book that I am trying to solve..I need to
I am trying to solve this exponentiation problem . Here is the code that
I'm having a strange problem, that I've been trying to solve for too long.
I'm trying to solve a problem that, unfortunately, goes beyond my capacity. I have
Here's the problem I'm trying to solve: I have a dynamic php-driven website that
I'm trying to solve the following problem: I have a download button that when
I'm trying to write a trigger to solve innodb auto_increment problem. I want to
so here is the problem i'm trying to solve, i want to use a

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.