⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webapp-faq.xtp

📁 RESIN 3.2 最新源码
💻 XTP
字号:
<document><header>  <product>resin</product>  <title>Web Applications FAQ</title>  <description>  </description></header><body><summary objsummary="localtoc"/><s1 name="forward-path" title="How are path related values of the request object changed after a forward or include?" type="faq"><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><p>The values of getRequestURI() and other path related method's change for aforward(), but remain the same for an include().  </p><s2 title="include"><p>When a servlet (or jsp) has been invoked by an include, the path relatedmethods of the <code>request</code> object correspond to the invokingservlet.  Request attributes <code>javax.servlet.include.*</code> contain valuescorresponding to the target.</p><deftable title="result of invoking calling include(target)"><tr><td>getXXXX() methods</td><td>invoking servlet</td></tr><tr><td>javax.servlet.include.</td><td>target</td></tr></deftable><example title="/testapp/index.jsp">&lt;jsp:include page="target.jsp"/&gt;</example><deftable title="path related methods in target.jsp after include"><tr><td>request.getRequestURI()</td><td>/testapp/index.jsp</td></tr><tr><td>request.getContextPath()</td><td>/testapp</td></tr><tr><td>request.getServletPath()</td><td>/index.jsp</td></tr><tr><td>request.getPathInfo()</td><td>null</td></tr><tr><td>request.getQueryString()</td><td>null</td></tr></deftable><deftable title="request attributes available in target.jsp"><tr><td>request.getAttribute("javax.servlet.include.request_uri")</td><td>/testapp/target.jsp</td></tr><tr><td>request.getAttribute("javax.servlet.include.context_path")</td><td>/testapp</td></tr><tr><td>request.getAttribute("javax.servlet.include.servlet_path")</td><td>/target.jsp</td></tr><tr><td>request.getAttribute("javax.servlet.include.path_info")</td><td>null</td></tr><tr><td>request.getAttribute("javax.servlet.include.query_string")</td><td>null</td></tr></deftable></s2><s2 title="forward"><p>When a servlet (or jsp) has been invoked by a forward, the path relatedmethods of the <code>request</code> object return the path of the targetservlet.  Request attributes <code>javax.servlet.forward.*</code> contain valuescorresponding to the invoking servlet.</p><deftable title="result of invoking calling forward(target)"><tr><td>getXXXX() methods</td><td>target</td></tr><tr><td>javax.servlet.forward.</td><td>invoking servlet</td></tr></deftable><p>From the discussion of forward() in the Servlet specification:</p><blockquote>The path elements of the request object exposed to the target servlet mustreflect the path used to obtain the RequestDispatcher.</blockquote><example title="/testapp/index.jsp?foo=bar">&lt;jsp:forward page="target.jsp"/&gt;</example><deftable title="path related methods in target.jsp after forward"><tr><td>request.getRequestURI()</td><td>/testapp/target.jsp</td></tr><tr><td>request.getContextPath()</td><td>/testapp</td></tr><tr><td>request.getServletPath()</td><td>/target.jsp</td></tr><tr><td>request.getPathInfo()</td><td>null</td></tr><tr><td>request.getQueryString()</td><td>null</td></tr></deftable><deftable title="request attributes available in target.jsp"><tr><td>request.getAttribute("javax.servlet.forward.request_uri")</td><td>/testapp/index.jsp</td></tr><tr><td>request.getAttribute("javax.servlet.forward.context_path")</td><td>/testapp</td></tr><tr><td>request.getAttribute("javax.servlet.forward.servlet_path")</td><td>/index.jsp</td></tr><tr><td>request.getAttribute("javax.servlet.forward.path_info")</td><td>null</td></tr><tr><td>request.getAttribute("javax.servlet.forward.query_string")</td><td>null</td></tr><tr><td>caucho.forward</td><td>true</td></tr></deftable></s2><s2 title="Exception: getNamedDispatcher()"><p>If getNamedDispatcher() is used to obtain a dispatcher to do the include() or forward(), no attributes are set.</p></s2><s2 title="Request parameters"><p>A call to forward() or include() can contain parameters in the url.  Theseparameters are returned with a subsequent call to request.getParameter().</p><p>The value of request.getQueryString(), however, depends on whether aninclude() or a forward() was done, and you may end up with the bizarresituation where the value of request.getParameter() does not match the value inthe query string.  </p><deftable title="include index.jsp"><tr><td>called with url</td><td>/testapp/index.jsp?foo=original</td></tr><tr><td>index.jsp contains</td><td>&lt;jsp:include page="target.jsp"/&gt;</td></tr><tr><td>request.getQueryString() in target.jsp returns</td><td>foo=original</td></tr><tr><td>request.getParameter("foo") in target.jsp returns</td><td>original</td></tr><tr><td>request.getAttribute("javax.servlet.include.query_string") in target.jsp returns</td><td>null</td></tr></deftable><deftable title="include index.jsp?foo=override"><tr><td>called with url</td><td>/testapp/index.jsp?foo=original</td></tr><tr><td>index.jsp contains</td><td>&lt;jsp:include page="target.jsp?foo=override"/&gt;</td></tr><tr><td>request.getQueryString() in target.jsp returns</td><td>foo=original</td></tr><tr><td>request.getParameter("foo") in target.jsp returns</td><td>override</td></tr><tr><td>request.getAttribute("javax.servlet.include.query_string") in target.jsp returns</td><td>foo=override</td></tr></deftable><deftable title="forward index.jsp"><tr><td>called with url</td><td>/testapp/index.jsp?foo=original</td></tr><tr><td>index.jsp contains</td><td>&lt;jsp:foward page="target.jsp"/&gt;</td></tr><tr><td>request.getQueryString() in target.jsp returns</td><td>null</td></tr><tr><td>request.getParameter("foo") in target.jsp returns</td><td>original</td></tr><tr><td>request.getAttribute("javax.servlet.forward.query_string") in target.jsp returns</td><td>foo=original</td></tr></deftable><deftable title="forward index.jsp?foo=override"><tr><td>called with url</td><td>/testapp/index.jsp?foo=original</td></tr><tr><td>index.jsp contains</td><td>&lt;jsp:foward page="target.jsp?foo=override"/&gt;</td></tr><tr><td>request.getQueryString() in target.jsp returns</td><td>foo=override</td></tr><tr><td>request.getParameter("foo") in target.jsp returns</td><td>override</td></tr><tr><td>request.getAttribute("javax.servlet.forward.query_string") in target.jsp returns</td><td>foo=original</td></tr></deftable></s2></s1><s1 title="Class.forName() doesn't seem to work right" type="faq"><description>When I do Class.forName(classname).getInstance() I do not seem to a newlyloaded Class Object. It seems that I always just get the cached old versionand not a new version if I compile a new Class into the classpath.</description><p>Class.forName(String) has a bit of an obscure feature, it uses the "definingclassloader of the current class" when it searches for the class.</p><p>To successfully accomplish the functionality of Class.forName() in all circumstances, you can use:</p><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);}</example></s1><s1 title="Why do I have to put my classes in a package?" type="faq"><description>If I make a class that is not in a package, Resin does not recognize it and does not load it.</description><p>Starting with Java 1.4 the use of classes that are not in a package (sometimescalled the "default" package") is deprecated.  Java classes should always be ina package.  In some version of Java, packageless classes are not going to besupported at all.</p><p>The solution is to put all of your classes in a package.</p><p>See<a href="http://java.sun.com/j2se/1.4/compatibility.html">http://java.sun.com/j2se/1.4/compatibility.html</a>, point #8, second bullet point.</p></s1><s1 title="How do I specify the default file encoding?" type="faq"><description>I want to specify the default file encoding for InputStreamReader andOutputStreamReader, using the system property <code>file.encoding</code>, butit doesn't seem to work.  </description><p>The default file encoding for the JVM is set with the system property<code>file.encoding</code>.  The JDK will only pick up that system property ifit is specified at startup:</p><example>$ bin/resin -Dfile.encoding=ISO-8859-1</example><p>A simple JSP can be used to determine the default encoding that is being used:</p><example title="file-encoding.jsp">&lt;%@ page session="false" import="java.io.*" %&gt;System.getProperty("file.encoding"): &lt;%= System.getProperty("file.encoding") %&gt;&lt;p&gt;OutputStreamWriter encoding is: &lt;%= (new OutputStreamWriter(new ByteArrayOutputStream())).getEncoding() %&gt;</example><results>System.getProperty("file.encoding"): ISO-8859-1OutputStreamWriter encoding is: ISO8859_1</results></s1></body></document>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -