getServletContext « API « JSP-Servlet Q&A





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

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    stackoverflow.com

html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Murach's Java Servlets and JSP</title>
</head>

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

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

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    coderanch.com

6. synchronize(getServletContext())    coderanch.com

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

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    coderanch.com

Hi there , While implementing MVC architecture , I made an abstract ParentController.java which is extended by ApplicationController.java. 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: ApplicationController.java:46: cannot resolve symbol symbol : method getServletContext () ...





11. getServletContext null pointer    coderanch.com

12. getServletContext() returning null    coderanch.com

import java.io.*; 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    coderanch.com





19. getServletContext().getResourceAsStream()    zkoss.org

Orignial message at: https://sourceforge.net/forum/message.php?msg_id=3857986 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 = iStream.read()) != -1){ sbSQLString.append((char) c); } log.debug("Script = ...

20. How to getServletContext in GenericForwardComposer    zkoss.org

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    forums.oracle.com

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

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 ...