servletcontext

Configuring Tomcat to only raise one Servlet per application

According to my understand, Tomcat is allowed to raise as many copies of a servlet as it wishes in order to service requests. This forces my servlets to have no heavyweight state, and instead store all state in the (singleton) servlet context. Is it possible to configure Tomcat to treat my servlets as singletons, and always raise exact...

Accessing ServletContext outside of a servlet

Hello I wonder if anyone can advise on a Java webapp question? I have a set standard Java class which has methods to set and get values of a property file. These methods are used system wide and are called by servlets and non-servlet class methods alike. But what I would like to do is to use a ServletContextListener to set the paths ...

Why use the ServletContext object in a web-app containing servlets and "worker" threads in Java

Hi, I currently have a web-app where I have Servlets reading and writing to the ServletContext attributes and I have "working" Threads (Daemon threads) which get initialized on startup and currently hold as a member the ServletContext object. For a couple of reasons I'm thinking of moving to "implement Runnable" instead and I'm kind of s...

purpose of webAppRootKey ?

Can somebody explain this entry in web.xml ? When it has to be used and why ? <context-param> <param-name>webAppRootKey</param-name> <param-value>webapp.root</param-value> </context-param> Is this something related to Spring or general one? ...

How can I list all deployed jax-ws webservices?

I have deployed some jax-ws webservices in a tomcat: web.xml: ... <servlet> <servlet-name>WebServiceJaxWs</servlet-name> <servlet-class>...a bean of mine which overwrites WSServletDelegate</servlet-class> <load-on-startup>1</load-on-startup> </servlet> ... The webservices themselves are defined in the sun-j...

Spring WebContent Resources - Access outside ServletContext

I have a Spring Web MVC application that I'd like to serve a large, partially generated file. I've added that file to my WebContent directory and all works fine there. However, I'd also like to access that file from my various build/deploy scripts, which read and parse the file. My current approach is to keep a copy of the file under t...

Can getAttribute() method of Tomcat ServletContext implementation be called without synchronization?

I would like to read some parameters during servlet initializtion (in init() method), and store them among servlet context attributes (using getServletContext().setAttribute()). I would like to read these parameters later - during some request processing (using getServletContext().getAttribute()). So, the multiple threads could do this s...

Parse XML file using JSP/JavaBean, deployed in WAR

I have a JavaBean that reads and processes an XML file. The XML file lives in the WEB-INF/ folder in my application. A JSP file uses the JavaBean to pass it the XML file name using the setProperty method, and uses the context path to do so. This works fine in my local development environment, but when deployed as a WAR on our test envir...

Jersey / ServletContext and resource loading on startup.

Hello, I'm kind of new in web development with Java. I am developing a web service and I've chosen REST / Jersey for it. I want to init some stuff on startup of the service and to keep them all along the life of the service. First question : Is the constructor of the Jersey Servlet a good place to do that ? Basically, what I want t...

ServletContext getResource not working

I'm trying to use ServletContext.getResource to retrieve a java.net.url 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 back a string URL. However, getResource always returns null. Example 1: String picture = ServletContext.getRealPath("pic...

Get servletcontext for factory class in spring

Hi ..., I want to create Factory Class. for example is FooFactory. before Foo instanced, FooFacoty must be injected ServletContext to the constructor. I have snippet as follows: public class FooFactory() { public static Foo getFoo() { ctx = //getservlet context Foo foo = new Foo(ctx); return foo; }...

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 web project I get a "cannot find symbol" on the getContextPath() method of the ServletContext interface It's driving me completely insane because in order to run my tests and so...

How to identify the URL of an Java web application from within?

My Java web application contains a startup servlet. Its init() method is invoked, when the web application server (Tomcat) is started. Within this method I need the URL of my web application. Since there is no HttpServletRequest, how to get this information? ...

Simple Servlet Question on ServletConfig instantiation

Apparently the following is generating a loop(the GenericServlet class is calling the subclass's init()) public void init() throws ServletException { ServletConfig c = this.getServletConfig(); super.init(c); } I'm probably just doing this wrong. Thank you guys in advance! ...

ServletContextListener and virtual hosts

Can anyone please tell me why ServletContextListener.contextInitialized() gets called once for each virtual host that's configured in jboss-web.xml? Is there is any way of having multiple virtual hosts while forcing contextInitialized() to only be called once? ...

FacesContext and "Servlet" Context

Hi, is there any equivalent to FacesContext, but in servlet environment? I have some DAOSessionManager that handles transaction to my database. I can use the FacesContext to identify the current http request when the current page is written using JSF, but what about servlet ones ? I can't find any way to get the current Servlet conte...

maven: add arbitrary file as a servlet context resource

I have a maven war project which produces webapp.war, and a maven 'skin' project which produces skin.zip (a file full of resources and XML files). Now I want to add this zip file as a servlet context resource (e.g WEB-INF/skin.zip). I tried using overlays, but it expands the zip file into WEB-INF instead of placing the un-expanded fi...

Java accessing ServletContext from within restlet Resource

I am using Tomcat server in java and wanted to be able to access the ServletContext from the restlet Resource in order to access my cached DataSource object (to pool mysql connections). org.restlet.resource.Resource comes with a Context object but that is not in any way related to the ServletContext. So after some googling around, I foun...

NullPointerException in a singleton when Tomcat is shutting down

I have apache tomcat 6 installed as a service on my windows xp machine. I have a class which implements ServletContextListener and it initializes a singleton required for the correct flow of the servlets (it does so on contextInitialized). The problem I'm seeing is that when I stop the service in windows (via services.msc) and I still ha...

servlet stores list in servlet context

hello, 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 needs to run only once. could some one please explain how to go about doing that. thanks ...