aspose file tools*
The moose likes JSP and the fly likes Url problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Url problem" Watch "Url problem" New topic
Author

Url problem

Priety Sharma
Ranch Hand

Joined: Jun 10, 2008
Posts: 156

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?


Priety.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Priety Sharma
Ranch Hand

Joined: Jun 10, 2008
Posts: 156

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

Joined: Jan 10, 2002
Posts: 61606
    
  67

Still using scriptlets?
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

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!


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Priety Sharma
Ranch Hand

Joined: Jun 10, 2008
Posts: 156

Hi ,

I have removed scriplet from the jsp and am using EL.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

You will be a better developer and a happier man for it!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Url problem