• Post Reply Bookmark Topic Watch Topic
  • New Topic

Please help me understand the purpose of application.getContextPath() in JSP  RSS feed

 
Harsh Bhasin
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am trying to understand a piece of JSP code and have gone through a few tutorials. But I am having hard time understanding what the following line of code trying to do.



My understanding is the current form (called appForm) is taking some action upon clicking a submit button.

But what is this action doing ?

In other words what is and is trying to do?

Thank you
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The context path is the part of a URL that tells the container which web context (web application) is to receive the request. It's frequently the same as the name of the war file. So if the web app is deployed as fred.war, the context path would be "/fred".

The remainder of the URL is the servlet path. It tells the servlet container which servlet to invoke and matches a servlet mapping.

In this code, the code is correctly obtaining the context path programmatically. It then looks up the servlet path from a constant string.

The only problem with this code is the use of scriptlet expressions, which have been obsolete for 15 years. It should be using the JSTL and EL.
 
Harsh Bhasin
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Bear.

So when I click Submit, the data is being sent to some web application (defined by the context path) . Is that correct ?

If so, should the context path be defined (as in what web application to send data to if it is something other than fred.war ) somewhere in the code?

Thank you
 
Harsh Bhasin
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To answer my own question .. I found where in the code the link for context path is defined.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. The context path is assigned by the container and the configuration. It is not in the code.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!