Thanks for your reply. Would you please give an example, cause I'm still confused.
Main Topics
Browse All TopicsHi, jsp gurus,
Can anyone tell what's the difference between request. getContextPath() and application.getRealPath("/
i tried to print out : contextPath=<%=request.get
Thanks for your attention.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Okay,
I have a webapp on my local machine called "scratchpad" where I do my development work. The url for the home page is
"http://localhost:8080/scr
If I have this code in my homepage
-----------------
HttpServletRequest.getCont
ServletContext.getRealPath
----------------
it outputs
---------------
HttpServletRequest.getCont
ServletContext.getRealPath
This is because the first outputs the name of the context (the webapp name). The second shows me the real path (the directory structure on the computer) of the webapp, i.e. where it can be found on my PC. Note that if you are developing in the root context (at url "http://localhost:8080/ind
Hope that explains everything.
Hi, thanks for your reply.
I'm using tomcat-5.5.7. My application is under : c:\jakarta-tomcat-5.5.7\we
When I use contextPath=<%=request.get
1.fileLists is the web application name (jsut a directory) , so it should return /fileLists ?
2. in tomcat, besides under the root directory, where the program could be put?
another question:
<%=getServletContext().get
<%=application.getRealPath
3.return same thing, could explain a little bit the reason?
4. also should i always use the "/" as a premeter in getRealPath("/") ?
Thanks for your reply.
>>1.fileLists is the web application name (jsut a directory) , so it should return /fileLists ?
Nope, it should return nothing as your are in the ROOT context.
>.2. in tomcat, besides under the root directory, where the program could be put?
Create a new webapp. all this means is creating a new folder in <tomcat_home>/webapps. Here's a walk through
create folder <tomcat_home>/webapps/test
go to http://localhost:8080/mana
Scroll down to:
>Install
>Install directory or WAR file located on server
in >WAR or Directory URL:>
type: "test" (with no quote marks) and click the install button.
There should now be a webapp called "test" in the list at the top.
Remember, unless you have a web.xml in your test/WEB-INF folder, if you restart tomcat, you will lose the "test" webapp.
3./They refer to the same object. "application" is an implicit object in a jsp like request and response. Just as request is the HttpServletRequest object for that page, application is the ServletContext object for the page and you are calling the same object with both.
4./To get the root of that webapp, yes.
Hi, thanks for your reply. Very clear.
When I try to go to http://localhost:8080/mana
I input the "admin" as user name ( no quotes ), click ok (pwd is blank).
The window is still there, it seems the pwd is not correct . Where i can find the admin. user name and pwd information?
Thanks for your reply.
now , i can access the manager page. when i scroll down to ( not install on the page, i'm using tomcat5.5.7))
>Deploy
>Deploy directory or WAR file located on server
there are several itemS need to be filled out
------------------------
Context Path (optional):
XML Configuration file URL:
WAR or Directory URL
--------------------------
i typed "test" (no quotes) in WAR or Directory URL , and click the deploy button. and i got a error message:
FAIL - Invalid context path was specified
since the context path is optional, i leave it blank
also there is an item
>WAR file to deploy
>Select WAR file to upload
do i need to fill this out ?
thanks for your reply.
maybe i'm using a different version of tomcat from yours.
>Deploy
>Deploy directory or WAR file located on server
------------------------
Context Path (optional):
XML Configuration file URL:
WAR or Directory URL
--------------------------
in the second box, it's not optional.
if scroll down the page, there is another upload file box for :
>WAR file to deploy
Select WAR file to upload
well, i guess i know too little about tomcat, as my qestion is too entry level.
thank you so much for your attention.
Business Accounts
Answer for Membership
by: bloodredsunPosted on 2005-04-06 at 14:35:04ID: 13721624
From javadocs
extPath()
(java.lang .String path)
ndex.html" , where contextPath is the context path of this ServletContext.
lPath("/") ;
HttpServletRequest.getCont
Returns the portion of the request URI that indicates the context of the request.
ServletContext.getRealPath
Returns a String containing the real path for a given virtual path. For example, the path "/index.html" returns the absolute file path on the server's filesystem would be served by a request for "http://host/contextPath/i
The real path returned will be in a form appropriate to the computer and operating system on which the servlet container is running, including the proper path separators. This method returns null if the servlet container cannot translate the virtual path to a real path for any reason (such as when the content is being made available from a .war archive).
-----------
Not to be confused with
getServletContext().getRea
which returns the path to the current webapp are you?