World class data recovery software and renowned raid recovery services

WestNIC provides reliable web hosting services

Ahosting.biz reseller hosting, managed dedicated server with 24/7 support

Site navigation below

This FAQ is part of the Code Style Help and FAQ section. Use the help request form below if your question is not answered here, but make sure you are asking the right question first.

Subscribe to this FAQ: RSS news feed

FAQ search

Servlet problems

Q: My custom error page doesn't show!

A: There are many things that could be wrong with your configuration. What happens when you force the error, which error page is issued? What does the error log tell you? Is the new configuration being deployed properly, to replace the previous one?

Check the webapps directory for the deployed web.xml file. Does it include your custom error configuration? Check the work directories under the Tomcat installation to see the which compiled JSP servlets are present. Perhaps there is a compilation error with your custom error page?

Q: I get a servlet 404 error at /examples/WEB-INF/classes/HelloWorld!

A: It appears you have deployed your servlet to the correct location, but you have probably not configured the servlet in the web.xml file for your application and you are requesting the wrong URL for the servlet. You should add web.xml entries like those below, restart and request the URL http://localhost:8080/examples/HelloWorld.

Premium Content: Follow this link for subscription information More details available to subscribers:
I get a servlet 404 error at /examples/WEB-INF/classes/HelloWorld!

Q: My servlet cannot locate my XSLT file!

A: On Windows systems, the path to files referenced in servlet classes should be given in full, including the drive letter and the path separator backslashes escaped.

Premium Content: Follow this link for subscription information More details available to subscribers:
My servlet cannot locate my XSLT file!

Q: The getRemoteUser method returns null after basic authentication!

A: Basic authentication details are carried in the HTTP headers that a browser passes to the servlet container when it makes a request. When the browser makes an initial request, it does not include an Authorization header, so the first servlet request.getRemoteUser() method returns null.

Your servlet must trigger the process by which the browser prompts for the login. The browser will then issue a second HTTP request with an Authorization header that carries the login details.

Premium Content: Follow this link for subscription information More details available to subscribers:
The getRemoteUser method returns null after basic authentication!

Q: I get "cannot find symbol" with getWrite()!

A: The HttpServletResponse class method for getting a PrintWriter is called getWriter(), not getWrite(), and may throw an IOException. The method may also throw the runtime exception UnsupportedEncodingException if the character set specified by the setContentType() method is not supported, and IllegalStateException if the getOutputStream() method has already been called.

Q: I get "cannot override doGet()" throwing an Exception!

A: This compiler error means that your method throws an exception that is not declared by the superclass method it is intended to override. The servlet doGet() method may throw a ServletException, an IOException or any subclass of those types. Since Exception is a superclass of the declared exceptions, it is not permitted.

If your doGet() method includes calls that may throw undeclared exceptions you should catch those exceptions and handle them. For example, you may report the problem in the servlet output, fall back to a simpler output or fixed error response, or throw a new ServletException with the details of the primary exception. If the exception originates from invalid servlet input, you may choose to send an HTTP 400, bad request, error response.

Servlet exceptions

Q: Could compiling a package cause an internal server error?

A: Possibly, but compiling a package wouldn't normally cause a 500 error directly. If you attempted to compile a servlet or a utility class on the host machine and the classpath environment setting was not configured properly, the classes would just fail to compile.

Premium Content: Follow this link for subscription information More details available to subscribers:
Could compiling a package cause an internal server error?

Q: What does this servlet stack trace mean: IndexOutOfBoundsException... ?

A: The answer to the question is in the first line of the stack trace. The interpreter attempted to get the array list item at index 4, but the size of the array list was zero. Whatever code was supposed to fill the list has not done so. To guard against this case, you should add a check for the size of the array before you reference an item at a specific index. This may be a symptom of concurrent modification of the array list by a separate thread.

Q: My file throws an AccessControlException!

A: The AccessControlException explains the problem without having to look any code extracts. The user profile that the servlet container is using does not have permission to access this file. Modify the permissions on the file to allow read access by the servlet container user if one exists. Otherwise, there may be a security policy for your servlet container that restricts the rights your applications have to access the file system. Check your servlet container documentation and adjust the configuration as necessary. The container may be configured with strict security policy by default.

Q: I get "HTTP GET method is not in use"!

A: The servlet you are referring to has not implemented the doGet(HttpServletRequest, HttpServletResponse) method, which is required to handle the type of requests made by typing the address into a Web browser. It is possible the servlet has been designed to handle HTTPpost requests from HTML form submissions only. In this case, you would have to create a form whose action attribute is the servlet URL with the method attribute post, as below.

Premium Content: Follow this link for subscription information More details available to subscribers:
I get "HTTP GET method is not in use"!

HTTP status errors

Q: Internet Explorer does not show my custom 500 error page!

A: The problem is with your browser, not your servlet container. Internet Explorer shows what it regards as "friendly" error messages when it receives HTTP error codes such as 500, 404, etc. This is a problem because it may obscure any genuinely helpful error messages you try to present to the user.

Premium Content: Follow this link for subscription information More details available to subscribers:
Internet Explorer does not show my custom 500 error page!

Q: My 500 error is java.lang.Exception!

A: It is very difficult to tell from this information alone what the problem is. The java.lang.Exception class is the superclass of all exceptions, so we cannot tell whether it is a runtime exception or checked exception thrown by your application. You should put debugging log output in your servlet to find the point at which the exception is thrown. Use the servlet method log(String) or log(String, Throwable).

If you have overridden the init(ServletConfig config) method, you must call super.init(config) in the first line of the method to enable these log methods.

Q: Why does my servlet give a 404 error?

A: There are many reasons why a servlet container may issue an HTTP 404 error for a servlet. You should check you have added a servlet configuration and mapping to your web.xml file and make sure you are requesting the URL path specified in the mapping.

If your servlet compiles successfully, another possibility is that it throws a ServletException in the init(ServletConfig) method. If so, the servlet container will log the exception and take the servlet out of service. Check your log files for any details.

Help request

Use the form below to submit a help request or general enquiry about the Code Style Web site. Before you write read the guidelines on asking the right questions, and check this page for periodic updates.

Information: Your email address will not be mis-used. If you include your address you may be sent a personal reply, you will not be added to any mailing list unless you request it. Read the site privacy statement for details.

Style warning - please read

Home · CSS · Java · Javascript · HTML · Help · Log