Place your text ad here.
World class Hard Drive Recovery and renowned raid recovery services
WestNIC provides reliable web hosting services
Free software downloads and drivers download resources
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.
/examples/WEB-INF/classes/HelloWorld!
getRemoteUser method returns null after basic authentication!
getWrite()!
Exception!
IndexOutOfBoundsException... ?
AccessControlException!
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?
/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.
More details available to subscribers:
I get a servlet 404 error at /examples/WEB-INF/classes/HelloWorld!
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.
More details available to subscribers:
My servlet cannot locate my XSLT file!
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.
More details available to subscribers:
The getRemoteUser method returns null after basic authentication!
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.
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.
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.
More details available to subscribers:
Could compiling a package cause an internal server error?
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.
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.
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.
More details available to subscribers:
I get "HTTP GET method is not in use"!
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.
More details available to subscribers:
Internet Explorer does not show my custom 500 error page!
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.
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.
A: The HTTP 405 status, "Method not supported", means that the submitted request method is not implemented by the servlet that handled the response. For example, a servlet may only have a doGet() method, not doPost(), and therefore be unable to issue an HTML document for the response body. In other words, the response means you can't make that kind of request for this servlet.
One common technique to easily enable a servlet to support POST requests is for the doPost() method to call the doGet() method, though some the HttpServletRequest object properties will vary from a normal GET request.
| Front-end FAQs | Back-end FAQs | Learning Java |
|---|---|---|
See site help for questions about this site, our text ads and sponsored links services.