ServletContext « Context « JSP-Servlet Q&A

1. initialize ServletContext using a method on a Resin server

Is there a way to initialize the ServletContext for a webapp on a Resin server using a method? I need something like that runs once, when the server starts up. ...

2. Is ServletContext one per web-app or one per JVM?

Here is the doubt I have come up with ServletContext is one per web-app and one per JVM. But if I am running more than one web-app on the same JVM. ...

3. ServletContext getResource not working

I'm trying to use ServletContext.getResource to retrieve a reference to an image file (which I will then include in a PDF library using iText). When I use ServletContext.getRealPath("picture.jpg"), I get ...

4. GET ServletContext in ServiceLayer

What is the best practice to get servlet context in service layer ?

5. ServletContext getContextPath()

I checked the javadocs of the Tomcat library I have included under my Netbeans project, and when I deploy the code works fine, but when I do a clean-build of my ...

6. Java ServletContext

I have a JSP web site, not Spring MVC, and it has a config file web.xml. There are a couple of settings within the web.xml file that I'd like to get. However, I ...

7. Shutdown Quartz scheduler

I have Quartz scheduler in my web application with Guice. I followed code found here. Everything works fine, but I can't figure out how to shutdown scheduler. My context ...

8. servlet stores list in servlet context

Moment the main servlet is deployed, it needs to perform calculations and prepare a list. this list needs to be accessed by the other servlet which are called subsequently. the calculation ...

9. Where to store a Servlet's singletons?

If my Servlet class uses a singleton (such as a manager class), where should it be stored? The servlet itself, or in the ServletContext? Can a servlet container create more than ...

10. Where is the servletContext available in Grails?

Where is the servletContext available in a Grails application? I tried to acces it in the Config.groovy but it didn't work. Access it in a view is also not possible. I want ...

11. What does "Context" in "ServletContext" mean?

Method getServletContextName() returns the name of the "web application". That means, "ServletContext" is nothing but "web application". Ok. API defines:

a ServletContextListener receives notifications about changes to the servlet context ...

12. How can I get ServletContext in my interceptor?

I have some initialization in my ServletContextListener. And I want to store some objects in ServletContext.

PropertiesUtil propertiesUtil = new PropertiesUtil(pathRole);
context.setAttribute("propertiesUtil", propertiesUtil);
But I have a problem. I can't get my value propertiesUtil ...

13. How to delegate ServletContext?

I want to override the ServletContext.getResource() method. So as to manage .jsp files myself, rather then put all .jsp files under webapp/ directory. Currently, I can patch on Jetty server, or Tomcat ...

14. Accessing the ServletContext from JS

I figured out how to grab the ServletContext on the java end looking at this thread, but I still am unsure how to grab it in the JS. I ...

15. How to gain access to a ServletContext instance from any method?

Is there any way to get access to the ServletContext from a method without passing the ServletContext as an argument? I need to have a generic Configuration class that can work on ...

16. ServletContext.getAttributes("Name") returns null

I have written servlet.I want to test the functionality of init() method of my servlet.But when I written a test case for my servlet with servletRunnermIt gives following exceptions.Also I got ...

17. The method getContextPath() is undefined for the type ServletContext

Here is my JSP:

path : <%= application.getContextPath() %>
This file is correct in Tomcat7 and Tomcat6, but when I request the JSP page in Tomcat 5.32 of my Cpanel hosting, I ...

18. start all servlets at application launch

I have a web application which has two servlets that exchange information through context attributes. Each servlet depends on the information that the other servlet sets in the context attributes. For example ...

19. getClassLoader() from ServletContext leads to AccessControlException

I'm trying to do the following (running in Jetty 8):

public class FooListener implements ServletContextListener {
  public void contextInitialized(ServletContextEvent event) {
This is what I'm getting: ...

20. Grails 2.0 and servletContext

I'm trying to access servletContextin a controller like so, but keep getting null pointer exception:

def servletContext = getServletContext()
def serverPath  = servletContext.getRealPath("/")
... I've come across that issue on mailing lists once ...

21. Store PrivateKey in ServletContext

I would like your opinion. I am developing a Servlet that has to sign the requests that it sends to an endpoint. In order to avoid read from file the server's ...

22. ServletContext

I tried this in the init() method of a class that similar to the current implementation of QuartzInitServlet: String[] jobGroups = scheduler.getJobGroupNames(); for (String jobGroup : jobGroups) { String[] jobNames = scheduler.getJobNames(jobGroup); for (String jobName : jobNames) { JobDetail jobDetail = scheduler.getJobDetail(jobName, jobGroup); jobDetail.getJobDataMap().put(SERVLET_CONTEXT_KEY, getServletContext()); } } And accessed the context like this: JobDataMap jobData = context.getJobDetail().getJobDataMap(); ServletContext servletContext = (ServletContext) ...

23. Getting Servletcontext from Quartz job

Hello I have a Quartz job running inside ApacheTomcat where a ServletContextListener initiates a Quartz ScheduleController which 'submits' the job in question. Is it possible to access ServletContext from the execute method of the job's class, i.e. the one which implements the job interface? Or even from the class of the submitted job? I have tried setting a variable in the ...

24. ServletContext returns NULL

Hi, We deployed our application in iPlanet 6.0 on Solaris. Our report links are routed thru one "intermediate" jsp file for getting the configuration values. Configuration values are read and kept in application scope in first time invocation of any report, using application.setAttribute("reports_properties", properties); and subsequent call to reports will take the config values from application object. Application is working fine ...

25. plugins in ServletContext

27. ServletContext

ya....i have checked ...but there are methods through which i can get pieces of URL....... there is no method which gives complete URL i think i need to concatenat all those pieces to form a Complete URL... is there any other way other than this .....plzz let me know Thank you kee

30. ServletContext

31. servletcontext

32. ServletContext

33. ServletContext

35. ServletContext

36. Servlets and ServletContext

37. Question about ServletContext

38. Shared data through ServletContext

I have used the servlet context to store objects, without much trouble. The object i store are value objects (simple name value pairs in a HashMap) Perhaps there is a problem with the object you are storing? For example, if there is a certain field that doesn't serialize well, like a db Connection? I'm really not sure if this would be ...

39. ServletContext.getRealPath()

40. ServletContext : Please Help

41. ServletContext size constraints?

Hi - I am writing an uncomplicated servlet-based application which queries one db table and retrieves a subset of its data for JSP/HTML display. I was thinking about saving the entire table (a few thousand rows) to the ServletContext at application startup time. Then, subsequent retrievals could run against this saved version. I'm pretty sure this would be _much_ faster than ...

42. When ServletContext is initialized

43. ServletContext v/s init()

44. a question about the ServletContext

hi vrussell , where u have that Video object(i mean class file)? in /servlet directory with other servlets?? if so move it from there to the server classpath. it should work. i tried put that in my /servlet directory. it compiles. but it gives me runtime ClassCastException which is precisely u r getting. i also did put a Vector in the ...

45. Problem with ServletContext

46. servletContext

47. saving to ServletContext

49. Notify JSP that ServletContext been changed?

the flow is client-> servlet->Bean, servlet->client, servlet->JSP->Bean. client calls servlet, servlet sends response back to client and writes data to Bean, mean while servlet also calls JSP to read from Bean. i know if I use response.sendRedirect() in Servlet, then there are some I can use to make JSP refresh. but in my case, since response has been sent to ...

50. ServletContext

51. ServletContext and thread safe

52. Since ServletContext's getServlet(...) is deprecated, how do i get a servlet?

I just don't want to have to forward to a url every time I want to use a servlet that does processing. In asp there was a way that you could execute another asp page (like a servlet), passing it the request/response objects, but never leave the page you're on. That means you don't have to make a trip out to ...

54. Sharing ServletContext

55. Strange ServletContext behavior

package com.gthought.framework.action; import javax.servlet.*; import javax.servlet.http.*; import*; public abstract class Action extends HttpServlet { //Method to catch POST requests public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { ServletConfig config = this.getServletConfig(); //Going to process the same method for both GET and POST processRequest(request, response, config); } //Method to catch GET requests public void doGet(HttpServletRequest request, HttpServletResponse response) throws ...

56. ServletContext, again

57. A Question in ServletContext

58. Using default ServletContext?

60. getResource in ServletContext

61. ServletContext

62. ServletContext problem

It could be a caching problem with the browser, or it could be with your code. It's hard for us to say from here. If it's a caching issue there are various techniques for telling the browser, and server not to cache content such as the no-cache meta tag: There are issues with both MSIE and netscape that ...

63. Accessing the servletContext outside of a servlet

This may be a stupid question, but i am trying to create a "global" database connection object for my web app using a servletContextListener and setting it as a context attribute. I have a plain old bean that i want to get the connection from the servletContext but cannot. Inside my bean i have: ... Connection con = (Connection) getServletContext().getAttribute("DbStudents"); ... ...

64. ServletContext problem

65. ServletContext over distributed JVMs

66. ServletContext Confusion...

68. ServletContext InitParameter Problem

69. The ServletContext

71. Get webapp name with ServletContext

72. ServletContext AttributeListener

I didn't put it in a package, I just put it in the classes directory of WEB-INF. Does it definatley need to be in a package? I'm always told packages are a good idea, but didn't think it was a mandatory requirement in this situation. [ December 13, 2005: Message edited by: colin shuker ]

73. Servletcontext

74. getting Servletcontext in a class

Hi I'm pasting my code for the class public class DWRFacade extends HttpServlet { public Set getCounties(int stateId){ Set setCounties = null; List lstStateMaster= (List)getServletContext().getAttribute("lstStateMaster"); StateMaster state; for(int i=0; i

75. ServletContext in real environment

77. Default Web application/ ServletContext

yes, we can deploy independent servlets every container has a default web app folder e.g Tomcat has ROOT in its webapps folder this ROOT is the default webapp if we store servlet here and in Tomcat conf file if the invoker servlet is enabled (not commented out)then our servlet can be called as server/servlet/MyServlet

78. ServletContext AttributeListener problem

package pack1; import*; import*; import javax.servlet.*; import javax.servlet.http.*; import javax.swing.*; public class ShowFrame extends HttpServlet implements ServletContextAttributeListener { private JFrame frame; private JLabel label; public void init() { frame=new JFrame("Frame"); label=new JLabel("NONE"); label.setSize(100,20); label.setLocation(10,10); frame.setSize(300,200); frame.getContentPane().setLayout(null); frame.getContentPane().add(label); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.getServletContext().setAttribute("name","value"); response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); /* TODO output ...

79. ServletContext AttributeListener again

80. ServletContext

81. ServletContext doubt ?

83. ServletContext.getRealPath

85. getting reference to the servletContext

86. ServletContext

In which case that code is just not going to work. You can't reliably call getRealPath for a path inside a war file (as the JavaDocs for getRealPath() say). You will need to change the code to either get the location of the path from somewhere else, or load whethever you need from the war file as a resource via the ...

87. how to get servletcontext name in a JSP

Hi, i have to get the servletcontext name in my application. Eg: http://localhost:8080/myapplication/index.jsp, here i have to get the servletcontext/webapp name (i.e. myapplication) in my app. But here, i should not use request.getContextPath(); as this comes from the browser URL. The reason is, For my application i am not giving the direct URL of server to client. Client access the application ...

92. Why use ServletContext?

93. i need help for ServletContext

hello everybody Actually i'm trying to type a ServletContext but i Got the following Error contextDestroyed(javax.servlet.ServletContextEvent ) in MyLis tener cannot implement contextDestroyed(javax.servlet.ServletContextEvent ) in ja vax.servlet.ServletContextListener; overridden method does not throw java.lang.E xception public void contextDestroyed(ServletContextEvent sce)throws Exception ^ contextInitialized(javax.servlet.ServletContextEve nt) in MyL istener cannot implement contextInitialized(javax.servlet.ServletContextEve nt) i n javax.servlet.ServletContextListener; overridden method does not throw ng.Exception ...

94. ServletContext cannot be resolved to a type