Java (JSP/Servlet): equivalent of getServletContext() from inside a .jsp

Posted by Webinator on Stack Overflow See other posts from Stack Overflow or by Webinator
Published on 2010-05-24T16:11:45Z Indexed on 2010/05/24 16:21 UTC
Read the original article Hit count: 1083

Filed under:
|
|

How should I access the ServletContext from a .jsp? For example, how can I call the getRealPath method from inside a .jsp.

Here's a Servlet, which works fine:

protected void doGet(
            HttpServletRequest req,
            HttpServletResponse resp
    ) throws ServletException, IOException {
        resp.setContentType( "text/html; charset=UTF-8" );
        final PrintWriter pw = resp.getWriter();
        pw.print( "<html><body>" );
        pw.print( getServletContext().getRealPath( "text/en" ) );
        pw.print( "</body></html>" );
        pw.flush();
        pw.close();
    }

Now I'm looking for the exact line I'm supposed to insert in the following .jsp to do exactly the same thing as the servlet above is doing.

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <body>
     ...  // What should I insert here   
  </body>
</html>

© Stack Overflow or respective owner

Related posts about java

Related posts about jsp