This section demonstrates you to get the absolute path in jsp. The absolute path is the full path that contains the root directory instead of a few directories contained within the absolute path. The absolute path always begin with a / (slash). You can see in the given example, in order to get the absolute path of jsp file, we have used the method getServletContext().getRealPath("/").
Understand with Example
The Tutorial illustrate an example from 'JSP Absolute Path'. To understand JSP Absolute Path example we create a a html tag that embeded the java expression. The HTML can be turned into jsp by changing the extension of .html into absolute .jsp. The following text code is put in a file called AbsoluePath.jsp. Place the Absolute.jsp into your JSP directory and able to view in browser.
<%= getServletContext().getRealPath("/")> : The <%=> is used to embed Java expression in JSP pages The getServletContext().getRealPath("/") method is used to get the absolute path of jsp file. The absolute path is the full path that gives you the information about the root directory in which jsp file is placed.
Here is the code of AbsolutePath.jsp
Absolute Path is:<%= getServletContext().getRealPath("/") %>
Following output will be displayed on the browser:
Posted on: June 15, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles