• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with url paths

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

/springbeginner/authentication/registerpage

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.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Mr. Bill. I will check
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic