Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

With and without /

 
Ranch Hand
Posts: 212
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a simple question:

Whats the difference between

and


 
Saloon Keeper
Posts: 15484
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first is a path relative to your current page, while the second is a path relative to the root of your application.
 
raja singh kumar
Ranch Hand
Posts: 212
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

the second is a path relative to the root of your application.



Example is the name of my project and also the context root. I am using websphere server which uses 9080 as the default port. I have mentioned the form tag with action in my html file.

I access my html form as:

http://localhost:9080/Example/index.html

When I mention / in the front in the action attribute like this (/a), on submission of the html form the url becomes

http://localhost:9080/a

How are you saying it is a path relative to the root of the application? The root in the case of this application is Example, but that disappears on the submission of the form.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a Java web application, URLs should start with the context path, which you can obtain programmatically in your JSP or servlet. See the JspFaq for more info.

As you have noted, without it, the "/" makes the URL relative to the server, not the web application.
 
Stephan van Hulst
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, my apologies, I meant the server.
 
raja singh kumar
Ranch Hand
Posts: 212
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have gone through the JSP Faq

So when I use / at the starting of the url in the action attribute of the form, it is a server-relative path?

When I dont use / at the starting of the url in the action attribute of the form, it is a page-relative path?

Please correct me if I am wrong.
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as you shown the

1.<form action ="url">

is called An absolute URL which normally indicates current url and

2.<form action = "/url">

is called  A relative URL which indicates the root of the application url.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Purvi Barot wrote:as you shown the

1.<form action ="url">

is called An absolute URL which normally indicates current url and

2.<form action = "/url">

is called  A relative URL which indicates the root of the application url.



Purvi, it's fine to reply to old posts when you have useful information to add. But a post like this one, which is completely wrong, maybe you should think twice before posting it?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic