servlets

Catching exceptions with tomcat and a servlet

I have set-up tomcat to catch all my exceptions and pass them to a servlet with the following in web.xml. <servlet-mapping> <servlet-name>exception</servlet-name> <url-pattern>/exception</url-pattern> </servlet-mapping> <error-page> <exception-type>java.lang.Exception</exception-type> <location>/exception</location> </er...

How do I report an error midway through a chunked http repsonse if I'm willing to close the connection?

(See related question: http://stackoverflow.com/questions/162917/how-do-i-report-an-error-midway-through-a-chunked-http-repsonse-without-closing) In my case, the #1 desire is for the browser to display an error message. No matter how uninformative. Closing the ServletResponse outputStream obviously doesn't work. Neither does throwing...

Is it possible to add to the available parameters of a request (HttpServletRequest)

I want to intercept a request in a filter/servlet and add a few parameters to it. However, the request does not expose a 'setParameter' method and the parameter map when manipulated throws an error saying it is locked. Is there an alternative I can try? ...

ArrayIndexOutOfBoundsException in XMLEntityScanner.peekChar reading XML from HttpRequest

I'm reading XML data from the HttpServletRequest in my servlets doPost() and passing the Reader from req.getReader() to a JAXB unmarshaller. I've tried a couple of different input XMLs but I always get this exception. SEVERE: Servlet.service() for servlet RESTPhotoAdmin threw exception java.lang.ArrayIndexOutOfBoundsException: 8192 ...

Is CGI in any way bettern than Servlets?

We have a web reporting application that was built with cgi (C/C++) 10 years back. Due to performance and security issues, it needs to be rearchitectured. What could be the best technology solution to re-engineer the cgi based architecture? ...

Loading JSP pages from custom sources

Would it be possible to execute a JSP page and capture its output outside of a web application? Mode specifically, in my case there still exists a usual web application, but it loads JSP pages not from its classpath, but from an arbitrary source. It seems like I cannot simply get RequestDispatcher and point it to a JSP file on disk. ...

How would you implement an RSS feed in a Java web environment?

I am working on an implementation for RSS feeds for a collaboration platform. Say there are several thousands of different collaboration rooms where users can share information, and each needs to publish an RSS feed with news, changes, etc... Using a plain servlet (i.e. http://www.site.com/RSSServlet/?id=roomID) is costly, every time an...

Custom ID in session handling by Java Servlet API

Is it possible to assign a custom ID to a HTTP session through Servlet API? I know that session handling from any application server, Tomcat for example, it's enough good to generate unique IDs. But I have custom unique session IDs based on information per user and time, so it won't be repeated. And I looked at every documentation abou...

How do I create a named log in $TOMCAT_HOME/logs for my servlet?

I'm currently logging via the simplest of methods within my servlet using Tomcat. I use the ServletConfig.getServletContext().log to record activity. This writes to the localhost.YYYY-MM-DD.log in $TOMCAT_HOME/logs. I don't want to get away from the simplicity of this logging mechanism unless absolutely necessary. But I would like to...

Java Servlets: Performance

I am working on a web application in Java which gets data from servlets via AJAX calls. This application features several page elements which get new data from the server at fairly rapid intervals. With a lot of users, the demand on the server has a potential to get fairly high, so I am curious: Which approach offers the best performa...

How do you develop Java Servlets using Eclipse?

I would like to program Java servlets using Eclipse and I plan on deploying them using Tomcat. I think I can build the projects using Ant which is bundled with Eclipse. I have the standard Eclipse IDE. What options do I have for doing Servlet development in Eclipse? What changes do I need to make to Eclipse? Do I need to install a plug-i...

Stripes: all URLs resolved through StripesDispatcher and forwarded to pre-compiled JSPs

Is it possible to have the StripesDispatcher be the sole determiner of webserver urls by looking at the @UrlBinding annotations on action beans AND also having those action beans forward to pre-compiled JSPs / servlets WITHOUT needing to define and maintain <servlet> <servlet-mapping> pairs in web.xml? Basically, I just want to have to o...

How do you make Eclipse recognize JEE jar files so Servlets can compile?

I am setting up my Java EE version of Eclipse to compile Servlets. I have the problem where Eclipse says "HttpServlet" cannot be resolved because it can't find the JEE jar files. I am using Windows XP. I already have Tomcat 6.0 up and running. I think the easiest solution would be to link to the servlet-api.jar file in the Tomcat instal...

Managing file uploads in JSP/Servlets

Once again a very beginner-ish question, but here I go: I would like to use a servlet or similar to copy an uploaded file (from an html file select) to a permanent location. This is all I need to do with the file. I am currently going with using the Apache Commons FileUpload and IO libraries. Is there no easier or more elegant solution?...

Can anyone explain servlet mapping?

I'm trying to write a web application using SpringMVC. Normally I'd just map some made-up file extension to Spring's front controller and live happily, but this time I'm going for REST-like URLs, with no file-name extensions. Mapping everything under my context path to the front controller (let's call it "app") means I should take care ...

Best way to manage database connection for a Java servlet

What is the best way to manage a database connection in a Java servlet? Currently, I simply open a connection in the init() function, and then close it in destroy(). However, I am concerned that "permanently" holding onto a database connection could be a bad thing. Is this the correct way to handle this? If not, what are some bette...

How to prevent a user from seeing previous users' info by hitting the "Back" button

I am developing a java web app using servlet, in order to prevent user from hitting the back button to see previous users' info, I have the following code : protected void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { HttpSession session=request...

Why HttpServletRequest.getRemoteAddr() doesn't work in Java servlet ?

I'm developing a web app with java servlet, I hope to get the user ip info by calling request.getRemoteAddr() from inside : processRequest(HttpServletRequest request,HttpServletResponse response) But it returns a wrong ip, since I'm not very knowledgeable about this area, I don't know what it is displaying, maybe a proxy, I got this : ...

Is there a convenient way to do analytics of a servlet?

Traditional logfile analytics tools (awstats, statcounter) or general web analytics (google analytics, yahoo web analytics) are not suitable for analyzing traffic on servlets. Is there a good alternative to log messages using a logging framework (log4j for example) and to write a custom analytics software for these? ...

Controlling the classpath in a servlet

My servlet application includes a number of library .jars, some of which contain embedded log4j.xml or log4j.properties files. I'd like to ensure that log4j finds my log4j.xml first! I've tried searching for some specification of the priorities of the various classpath elements in a servlet (e.g. does WEB-INF/classes always precede WEB-I...