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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:32:00+00:00 2026-05-26T08:32:00+00:00

I am learning the Spring MVC 3 now. I meet some problems when set

  • 0

I am learning the Spring MVC 3 now.

I meet some problems when set the URLs in my page, since the URL in the page are relatived to the current page, so I want to set the base URL in each page.

When I use Structs 2, I create a BaseAction like this:

public class BaseAction{
  public BaseAction(){
     string baseURL=getServletContext.getHost()+"...."+.....;
  }
  public getBaseURL(){xxxxx}
}

Then in the page:

<base href='<s:prototype value="baseURL"/>' /> 

Now, in Spring MVC 3, since the a new instance of related controller is not created for each request, so I do not know how to make it?

Finally, I think I can use the interceptor, so I create a interceptor:

public class BaseURLInterceptor extends HandlerInterceptorAdapter{

    public boolean preHandle(HttpServletRequest request, 
        HttpServletResponse response, Object handler)
        throws Exception {
        return true;
    }

    //after the handler is executed
    public void postHandle(
        HttpServletRequest request, HttpServletResponse response, 
        Object handler, ModelAndView modelAndView)
        throws Exception {
        modelAndView.getModel().setObject("baseURL",requset.getHost()+"......");
    }

}

In the page:

I can use :

<base href="${baseURL}" />

It works, however when a view is redirected, it will add this value to the URL.

For example:

@Controller
@RequsetMapping("/user")
public class UserController{

    @RequsetMapping("edit/{userid}")
    public String edit(@PathVariable String uid)
        //edit logic
        return "redirect:list"
    }

    @RequsetMapping("list")
    public String list(){
        //get users list
        return "user_list"
    }
}

When I make the submit button in the user edit page, I will redirect to :

http://localhost:8080/app/user/list?baseURL=http://localhost:8080

Where the parameter in the url ?baseURL=http://localhost:8080 is not what I want.

How to fix it?

Or what is the better way to solve the URL path using Spring MVC 3?

  • 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-26T08:32:01+00:00Added an answer on May 26, 2026 at 8:32 am

    May I do not correct understand the problem, but if you want to have the base url in the jsp for some links than your approach is the wrong one.

    normaly you would do something like this:

    test

    And for redirects in the controller you can specify how the url has to be interpreted if you use RedirectView instead of returning the String “redirect:xxx”: the redirect view constructor RedirectView(String url, boolean contextRelative) can be used to specify context relative to the current ServletContext or relative to the web server.

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

Sidebar

Related Questions

I’m learning to use the MVC 3 Framework, but I'm having some problems understanding
I am learning spring-mvc and I am doing a simple crud. I have a
Currently learning Spring MVC with Spring 3, I'm trying to find the correct way
I am learning myself Spring MVC 2.5 mostly from the docs. Can someone explain
Hey, I'm pretty new in Spring MVC, and I'm learning the JSP tags and
I am learning spring mvc and hibernate. i have just finished simple site with
I'm learning Spring 3 MVC for a project I'll start soon for a client
I have been learning java spring hibernate MVC for 3 months and got pretty
I am learning both AJAX and the Java Servlet API (well, Spring MVC, which
I'm learning MVC and trying to follow some tutorials and this video http://channel9.msdn.com/Events/DevDays/DevDays-2011-Netherlands/Devdays002 In

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.