getServletContext « API « JSP-Servlet Q&A

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

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(

2. jsp getServletContext() error


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Murach's Java Servlets and JSP</title>

    <%-- import packages and classes needed by the scripts --%>

3. I am getting null for getServlet().getServletContext().getRealPath("")

That is because path do not exist. I am not sure how the path structure in weblogic. you may need to ask it in weblogic forums. Regards Dheeraj Joshi

4. JSP using getServletContext Error

6. synchronize(getServletContext())

7. Question getServletContext().getRequestDispatcher("/foo.jsp").forward(req, res); I

With "/foo.jsp" you are addressing the page as if it is at the root directory of the server - but from the other URLs it looks like it lives at: /InScopeFortKnox/IWA/login/foo.jsp There is also a problem with this tag The attribute is not "lifespan" but "scope" and you need to have it set to "request" not ...

8. servlet cant see getServletContext() from inheritance

Hi there , While implementing MVC architecture , I made an abstract which is extended by In the ApplicationController I am doing : // get the application object ServletContext app = getServletContext(); // select login.jsp as the template RequestDispatcher disp; disp = app.getRequestDispatcher("index.jsp"); and at compile time I am getting: cannot resolve symbol symbol : method getServletContext () ...

11. getServletContext null pointer

12. getServletContext() returning null

import*; import javax.servlet.*; import javax.servlet.http.*; public class Versionservlet extends HttpServlet { ServletContext ctx = null; public void init(ServletConfig cfg) throws ServletException { System.out.println("-----------------------------"); System.out.println(" Versionservlet started "); System.out.println("-----------------------------"); } public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); pw.println("The version Servlet Started..........."); ctx = getServletContext(); pw.println(ctx.getMajorVersion()); pw.println(ctx.getMinorVersion()); } }

13. getServletContext() error

19. getServletContext().getResourceAsStream()

Orignial message at: By: davetam Hello, In the java code I need to read in a file as stream. In the past we can do it like this: void initialiseSQLStatement(String resourcePath){ try{ log.debug("Trying to open " + resourcePath); InputStream iStream = servlet.getServletContext().getResourceAsStream(resourcePath); int c; StringBuffer sbSQLString = new StringBuffer(); while ((c = != -1){ sbSQLString.append((char) c); } log.debug("Script = ...

20. How to getServletContext in GenericForwardComposer

I think you're still going to have a problem. The fact that your getHibernateFactory() is a static method means that no call to an instance method is allowed. If you *really* need getHibernateFactory() to be static, then you're going to have to get the servlet context before you call that and pass it in. If you don't need it static (and ...

21. getServletContext() method

22. servlet init block doesn't work with getServletContext().getRequestDispat..

Hi Everyone, I am getting null pointer exception when i have coded init method inside my servlet(inside that i am fetching init parameter passed from web,xml file) and while getting requestdispatcher from context. if i get requestdispatcher from request then it works fine. i dont understand reason behind this behaviour. please give your valueable comment. find code below: public void init(ServletConfig ...