File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes Problem with url paths Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Problem with url paths" Watch "Problem with url paths" New topic

Problem with url paths

chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Hi all, I am writing a sample login application. All my pages are under WEB-INF/jsp/ folder, only welcome page is in the root directory which in turn will forward the request to a page in WEB-INF/jsp/ directory using a controller.

My problem is with the relative paths. My project structure is:
In my webapp/welcome.jsp page the code is

This will forward the request to a WelcomeController in which I am resolving the view like this

This is my web.xml

This is how my beginner-servlet.xml looks likeMy AuthenticationConroller looks like this
The problem is when I forward the request to WEB-INF/jsp/welcome.jsp page the links is the page are getting a relative path like this


Now when I click on the register link it goes to AuthenticationController's showRegistrationForm method. It looks like this
Now in the register.jsp page I have some form with action mapped to a controller like thisNow the "back" link gets a relative path springbeginner/authentication/registerpage/welcome. When I click this it says 404 error. So I used This is hitting the WelcomeController. Is it good to put this ../../ in the code? or what approach should I take?

I hope all understood my problem. I think I explained a lot for a small problem, but I dint find any better way to explain. My apologizes.

Good day, thank you all in advance.

Love all, trust a few, do wrong to none.
Bill Gorder

Joined: Mar 07, 2010
Posts: 1681

Is it good to put this ../../ in the code? or what approach should I take?

sure or alternatively use JSTL to create URL's which will prefix the context root.

for example if welcome is right off your context root, it might look something like below:

On a side note if I understand what I think your doing you are reinventing the wheel. You should take a look at spring-security for this sort of thing.

[How To Ask Questions][Read before you PM me]
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Thank you Mr. Bill. I will check
I agree. Here's the link:
subject: Problem with url paths