<document>
<description> When I have a jsp "index.jsp" and it does a forward to "target.jsp", request.getRequestURI() returns the path for "target.jsp". How can I get the value for the original uri? </description>

The values of getRequestURI() and other path related method's change for a forward(), but remain the same for an include().

When a servlet (or jsp) has been invoked by an include, the path related methods of the `request` object correspond to the invoking servlet. Request attributes `javax.servlet.include.*` contain values corresponding to the target.

getXXXX() methods invoking servlet
javax.servlet.include.target
<jsp:include page="target.jsp"/>
request.getRequestURI()/testapp/index.jsp
request.getContextPath()/testapp
request.getServletPath()/index.jsp
request.getPathInfo()null
request.getQueryString()null
request.getAttribute("javax.servlet.include.request_uri")/testapp/target.jsp
request.getAttribute("javax.servlet.include.context_path")/testapp
request.getAttribute("javax.servlet.include.servlet_path")/target.jsp
request.getAttribute("javax.servlet.include.path_info")null
request.getAttribute("javax.servlet.include.query_string")null

When a servlet (or jsp) has been invoked by a forward, the path related methods of the `request` object return the path of the target servlet. Request attributes `javax.servlet.forward.*` contain values corresponding to the invoking servlet.

getXXXX() methods target
javax.servlet.forward.invoking servlet

From the discussion of forward() in the Servlet specification:

> The path elements of the request object exposed to the target servlet must reflect the path used to obtain the RequestDispatcher.

<jsp:forward page="target.jsp"/>
request.getRequestURI()/testapp/target.jsp
request.getContextPath()/testapp
request.getServletPath()/target.jsp
request.getPathInfo()null
request.getQueryString()null
request.getAttribute("javax.servlet.forward.request_uri")/testapp/index.jsp
request.getAttribute("javax.servlet.forward.context_path")/testapp
request.getAttribute("javax.servlet.forward.servlet_path")/index.jsp
request.getAttribute("javax.servlet.forward.path_info")null
request.getAttribute("javax.servlet.forward.query_string")null
caucho.forward true

If getNamedDispatcher() is used to obtain a dispatcher to do the include() or forward(), no attributes are set.

A call to forward() or include() can contain parameters in the url. These parameters are returned with a subsequent call to request.getParameter().

The value of request.getQueryString(), however, depends on whether an include() or a forward() was done, and you may end up with the bizarre situation where the value of request.getParameter() does not match the value in the query string.

called with url/testapp/index.jsp?foo=original
index.jsp contains<jsp:include page="target.jsp"/>
request.getQueryString() in target.jsp returns foo=original
request.getParameter("foo") in target.jsp returns original
request.getAttribute("javax.servlet.include.query_string") in target.jsp returns null
called with url/testapp/index.jsp?foo=original
index.jsp contains<jsp:include page="target.jsp?foo=override"/>
request.getQueryString() in target.jsp returns foo=original
request.getParameter("foo") in target.jsp returns override
request.getAttribute("javax.servlet.include.query_string") in target.jsp returns foo=override
called with url/testapp/index.jsp?foo=original
index.jsp contains<jsp:foward page="target.jsp"/>
request.getQueryString() in target.jsp returns null
request.getParameter("foo") in target.jsp returns original
request.getAttribute("javax.servlet.forward.query_string") in target.jsp returns foo=original
called with url/testapp/index.jsp?foo=original
index.jsp contains<jsp:foward page="target.jsp?foo=override"/>
request.getQueryString() in target.jsp returns foo=override
request.getParameter("foo") in target.jsp returns override
request.getAttribute("javax.servlet.forward.query_string") in target.jsp returns foo=original
<description> When I do Class.forName(classname).getInstance() I do not seem to a newly loaded Class Object. It seems that I always just get the cached old version and not a new version if I compile a new Class into the classpath. </description>

Class.forName(String) has a bit of an obscure feature, it uses the "defining classloader of the current class" when it searches for the class.

To successfully accomplish the functionality of Class.forName() in all circumstances, you can use:

<example> private Class classForName(String classname) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); if (loader != null) _theClass = Class.forName(classname, false, loader); else theClass = Class.forName(classname); } <description> If I make a class that is not in a package, Resin does not recognize it and does not load it. </description>

Starting with Java 1.4 the use of classes that are not in a package (sometimes called the "default" package") is deprecated. Java classes should always be in a package. In some version of Java, packageless classes are not going to be supported at all.

The solution is to put all of your classes in a package.

See http://java.sun.com/j2se/1.4/compatibility.html, point #8, second bullet point.

<description> I want to specify the default file encoding for InputStreamReader and OutputStreamReader, using the system property `file.encoding`, but it doesn't seem to work. </description>

The default file encoding for the JVM is set with the system property `file.encoding`. The JDK will only pick up that system property if it is specified at startup:

<example> $ bin/httpd -Dfile.encoding=ISO-8859-1

A simple JSP can be used to determine the default encoding that is being used:

<%@ page session="false" import="java.io.*" %> System.getProperty("file.encoding"): <%= System.getProperty("file.encoding") %> <p> OutputStreamWriter encoding is: <%= (new OutputStreamWriter(new ByteArrayOutputStream())).getEncoding() %> <results> System.getProperty("file.encoding"): ISO-8859-1 OutputStreamWriter encoding is: ISO8859_1 </results>
</document>