servlets

How do I implement a front controller in Java?

I'm writing a very simple web framework using Java servlets for learning purposes. I've done this before in PHP, and it worked by consulting the request URI, then instantiating the appropriate class and method. This worked fine in PHP, as one can do something like $c = new $x; $x->$y;. I'm unsure however of how to translate this to Java...

GlassFish problem with filter chain (has worked in Tomcat for years): java.lang.IllegalStateException: PWC3990: getWriter() has already been called for this response

We need to upgrade an elderly web application to run under GlassFish 3 instead of Tomcat in order to get EAR deployments (Glassfish was chosen as it is the reference JEE 6 implementation) Unfortunately it very quickly turned out that the mechanism that ensures that a user is logged in does not work properly and complains that getWriter(...

How Can I test Servlets with JUnit?

I saw Jetty has got and ServletTest class which you can use to test Servlets. tester = new ServletTester(); tester.setContextPath("/"); tester.addServlet(TestServlet.class, "/servlet/*"); ... tester.start(); Do you know if there is something similar in Tomcat? How could I test a servlet? ...

changing EPR in Axis2 wsdl

I am creating simple pojo webservice like TemperatureConversion. I was able to make deploy it and generate wsdl from it. The problem is that I want to change the EPR / address from "http://172.x.x.x:8080/MyWebservice/services/TemperatureConversion" to "http://172.x.x.x:8080/MyWebservice/TemperatureConversion" Is that possible? Thanks....

multiple error-code configuration web.xml

I'd like to direct all errors to my Errorsevlet without specifying all the codes explicitly. Is there any way to do like that? <error-page> <error-code>400</error-code> <location>/servlet/com.abc.servlet.ErrorServlet</location> </error-page> *And after reaching the ErrorServlet how can i get the stack trace of the error in the...

getting javax.servlet.ServletException: when running my eclipse on jboss?

I am getting javax.servlet.ServletException: when running my web application on jboss. I am not getting want to do. need help. below is the log; javax.servlet.ServletException: Failed to load application class: com.example.tutorials.TutorialsApplication com.vaadin.terminal.gwt.server.ApplicationServlet.init(ApplicationServlet.java:7...

In Java, How do I make sure my web application is thread safe?

How do I make sure my java servlets web application is thread safe? What do I need to do in regards to session variables, static variables of a class, or anything else that could be a thread-safety problem? ...

Set attribute into JSP PageContext for use in EL from a Filter

How can I put an attribute into the JSP PageContext for the current request (so that it becomes accessible via ${myVar} ) from a Filter that runs before the JSP? ...

How should response content type for documents be specified in order to work consistently across browsers?

I'm developing a simple servlet that should serve documents via http. I use URLs in the form of /getDocument?fileId=1234. The servlet simply 1) sets response.contentType and 2) writes to response.outputStream. The problem is about setting the content type correctly in order to have the browsers understand the response (i.e., display the...

How to implement pagination in Spring MVC 3

Hello, Is there any out-of-the-box, easy to implement, standard pagination component/tag-lib or code-sample available for pagination in Spring MVC? Cheers ...

How do I hide stack traces in the browser (using Jetty)?

I'm using Jetty as my servlet container. If an exception is thrown in one of my servlets the browser will display an HTTP ERROR 500 with the exception message and a stack trace. For security reasons I need to hide the stack trace. Is there a way to configure this generally? Or do I need to trap all Throwables in my Servlet? Thanks ...

How do I destroy and re-create the ServletContext in my J2EE app?

My question is basically the flip side of a previous question I asked. Is there a way to destroy (and then re-create) a (the?) ServletContext of a web application? Basically I'm trying to programmatically do whatever JBoss does to re-initialized the ServletContext - or just tell JBoss to do it for me. ...

running periodic task at server side for servlet JSP MVC website

I have developed a web application using using servlet and JSP. I am not using any framework per se ... instead using my own home brewed MVC framework I am using MySQL as a backend. I want to do the following cleanup some data from the data base every hour generate and store statistics about data every 15 minutes in an XML file some...

Include struts action result intro servlet

I have a question regarding Struts 2. Is it possible to include the result of a Struts action into a Servlet? I'm trying to use RequestDispatcher, but it doesn't work, so maybe others have different solutions. ...

Calling a servlet from a form but the servlet is never invoked

I am trying to call a Servlet called AddClass.java using the following line in a jsp <form method="post" name="addClass" action="AddClass.do"> The class is in package web and the filename is AddClass.java A similar servlet named SeedSearch is called (and everything works fine) from this piece of code in another jsp. <form method="po...

tools,plugins or api's for monitoring java web applications

hi all, I have developed a web application in java,i want to monitor the web application.I have used jconsole, but it monitors only java application.I heard about jmon could u tel me how to use jmon or any other tools or plugins are there for monitoring web applications.All your views are appreciated. ...

Jython and implementing HttpServlet.contextInitialized

I'd like my Jython servlet to implement the HttpServlet.contextInitialized method but I'm not sure how to express this in the web.xml. What I currently have is: from javax.servlet import ServletContextListener; from javax.servlet.http import HttpServlet class JythonServlet1 ( HttpServlet, ServletContextListener ): def contextI...

Implementing sessions in a java web server?

What's the best (most secure) way of implementing session handling in a web server? I'd like to add that, but don't know how to implement it really. Is cookies a "must" for session handling? (To be able to identify which session) ...

Servlet Dispatcher throwing exception

I have a simple Spring web flow application created. When the application starts, I get the following error on my Tomcat server: SEVERE: Servlet.service() for servlet dispatcher threw exception java.lang.NoSuchFieldError: WEB_APPLICATION_CONTEXT_ATTRIBUTE at org.springframework.webflow.mvc.servlet.ServletMvcView.doRender(Servle...

how to integrate jquery fullcalendar with jsp

events: [ { title: 'All Day Event', start: new Date(2010,2,13) }, { title: 'Long Event', start: new Date(y, m, d-5), end: new Date(y, m, d-2) } ] How to make this array in JSP after getting data from database? ...