• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Url problem

 
Priety Sharma
Ranch Hand
Posts: 156
Android Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scernario:
I have a servlet class named HelloWorldExample in my web apps web inf's classes folder.

I have a jsp in which the html's form tags action attribute is as follows:
action="servlet/HelloWorldExample"

When I submit the html file generated by this jsp, the request goes to the HelloWorldExample which does some processing and transfers control to another jsp.

This 2nd jsp's html's form tag also was as follows:
action="servlet/HelloWorldExample"

When I submitted the html fild generated by this 2nd jsp I get the following error:
resource /onlinelib/servlet/servlet/HelloWorldExample not found.

Why is this so?

For now I set the action element of the form tag of this 2nd jsp's html as follows:
onclick="sendForm('onlinelib/servlet/HelloWorldExample')"

which makes it work.

Why is this happening?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are using page-relative addressing (does not start with /). Bad news! You should be using server-relative addressing that starts with the context path. See the JSP FAQ for more information.
 
Priety Sharma
Ranch Hand
Posts: 156
Android Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

Sorry for my late reply.

Thanks for the information.
My problem is solved and am now setting the value of action as follows:
action="<%= request.getContextPath() %>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still using scriptlets?
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Still using scriptlets?


Indeed. Stop using it and access this value through EL.

It will look like: ${pageContext.request....} (I won't complete just for you have the pleasure to find it by yourself!)

Take a look at EL, it will better for your code and for you!
 
Priety Sharma
Ranch Hand
Posts: 156
Android Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I have removed scriplet from the jsp and am using EL.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will be a better developer and a happier man for it!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic