??xml version="1.0" encoding="utf-8" standalone="yes"?>久久亚洲精品无码观看不卡,红杏亚洲影院一区二区三区 ,色天使亚洲综合在线观看http://www.tkk7.com/meil/archive/2006/10/10/73908.html向东博客向东博客Tue, 10 Oct 2006 00:58:00 GMThttp://www.tkk7.com/meil/archive/2006/10/10/73908.htmlhttp://www.tkk7.com/meil/comments/73908.htmlhttp://www.tkk7.com/meil/archive/2006/10/10/73908.html#Feedback0http://www.tkk7.com/meil/comments/commentRss/73908.htmlhttp://www.tkk7.com/meil/services/trackbacks/73908.html 前一D|_(d)׃在处理Web应用下的文g创徏与移动等Q因此涉?qing)到很多关于java
中相对\径,l对路径{问题。同Ӟ对于Web应用中的相对路径Q绝对\径,以及(qing)Java.io.File
cd?fn)了一下。也找了一些资料。希望大安到类似的问题Q可以更有效的解冟?

=================================================================================
1.基本概念的理?/p>

  l对路径Q绝对\径就是你的主上的文件或目录在硬盘上真正的\径,(URL和物理\?例如Q?br />C:\xyz\test.txt 代表了test.txt文g的绝对\径?a >http://www.sun.com/index.htm也代表了一?br />URLl对路径?/p>

  相对路径Q相对与某个基准目录的\径。包含Web的相对\径(HTML中的相对目录Q,例如Q在
Servlet中,"/"代表Web应用的跟目录。和物理路径的相对表C。例如:(x)"./" 代表当前目录,
"../"代表上目录。这U类似的表示Q也是属于相对\径?/p>

另外关于URIQURL,URN{内容,请参考RFC相关文档标准?/p>

RFC 2396: Uniform Resource Identifiers (URI): Generic Syntax,
(http://www.ietf.org/rfc/rfc2396.txt)


2.关于JSP/Servlet中的相对路径和绝对\径?/p>

2.1服务器端的地址

   服务器端的相对地址指的是相对于你的web应用的地址Q这个地址是在服务器端解析?br />Q不同于html和javascript中的相对地址Q他们是由客L(fng)览器解析的Q也是说这时?br />在jsp和servlet中的相对地址应该是相对于你的web应用Q即相对?a >http://192.168.0.1/webapp/的?

  其用到的地方有:(x)
 forwardQservlet中的request.getRequestDispatcher(address);q个address?br />在服务器端解析的Q所以,你要forward到a.jsp应该q么写:(x)
request.getRequestDispatcher(?user/a.jsp?q个/相对于当前的web应用webappQ?br />其绝对地址是Q?a >http://192.168.0.1/webapp/user/a.jsp?
sendRedirectQ在jsp?lt;%response.sendRedirect("/rtccp/user/a.jsp");%>

2.22、客L(fng)的地址
 
       所有的html面中的相对地址都是相对于服务器根目?http://192.168.0.1/)的,
而不?跟目录下的该Web应用的目?http://192.168.0.1/webapp/的?
 Html中的form表单的action属性的地址应该是相对于服务器根目录(http://192.168.0.1/)的,
所以,如果提交到a.jsp为:(x)actionQ?/webapp/user/a.jsp"或action="<%=request.getContextPath()%>"/user/a.jspQ?br />  提交到servlet为actiomQ?/webapp/handleservlet"  
   Javascript也是在客L(fng)解析的,所以其相对路径和form表单一栗?
 

  因此Q一般情况下Q在JSP/HTML面{引用的CSS,Javascript.Action{属性前面最好都加上
<%=request.getContextPath()%>,以确保所引用的文仉属于Web应用中的目录?br />另外Q应该尽量避免用类?.","./","../../"{类似的相对该文件位|的相对路径Q这?br />当文件移动时Q很Ҏ(gu)出问题?/p>


3. JSP/Servlet中获得当前应用的相对路径和绝对\?br />3.1 JSP中获得当前应用的相对路径和绝对\?br /> 根目录所对应的绝对\?request.getRequestURI()
 文g的绝对\径  ? :application.getRealPath(request.getRequestURI());
 当前web应用的绝对\?:application.getRealPath("/");
 取得h文g的上层目?new File(application.getRealPath(request.getRequestURI())).getParent()

3.2 Servlet中获得当前应用的相对路径和绝对\?br /> 根目录所对应的绝对\?request.getServletPath();
 文g的绝对\径  ?:request.getSession().getServletContext().getRealPath
(request.getRequestURI())   
 当前web应用的绝对\?:servletConfig.getServletContext().getRealPath("/");
     (ServletContext对象获得几种方式Q?br />       javax.servlet.http.HttpSession.getServletContext()
       javax.servlet.jsp.PageContext.getServletContext()
       javax.servlet.ServletConfig.getServletContext()
     )

4.java 的Class中获得相对\径,l对路径的方?br />4.1单独的JavacM获得l对路径
  Ҏ(gu)java.io.File的Doc文挡Q可?
 默认情况下new File("/")代表的目录ؓ(f)QSystem.getProperty("user.dir")?br /> 一下程序获得执行类的当前\?br />package org.cheng.file;
import java.io.File;

public class FileTest {
    public static void main(String[] args) throws Exception {      

  System.out.println(Thread.currentThread().getContextClassLoader().getResource(""));    

  System.out.println(FileTest.class.getClassLoader().getResource(""));       

  System.out.println(ClassLoader.getSystemResource(""));       
  System.out.println(FileTest.class.getResource(""));       
  System.out.println(FileTest.class.getResource("/")); //Class文g所在\径?
  System.out.println(new File("/").getAbsolutePath());       
  System.out.println(System.getProperty("user.dir"));   
 }
}

4.2服务器中的Javac获得当前\径(来自|络Q?br />(1).Weblogic

WebApplication的系l文件根目录是你的weblogic安装所在根目录?br />例如Q如果你的weblogic安装在c:\bea\weblogic700.....
那么Q你的文件根路径是c:\.
所以,有两U方式能够让你访问你的服务器端的文gQ?br />a.使用l对路径Q?br />比如你的参数文件放在c:\yourconfig\yourconf.propertiesQ?br />直接使用 new FileInputStream("yourconfig/yourconf.properties");
b.使用相对路径Q?br />相对路径的根目录是你的webapplication的根路径Q即WEB-INF的上一U目录,你的参数文件放

在yourwebapp\yourconfig\yourconf.propertiesQ?br />q样使用Q?br />new FileInputStream("./yourconfig/yourconf.properties");
q两U方式均可,自己选择?/p>

(2).Tomcat

在类中输出System.getProperty("user.dir");昄的是%Tomcat_Home%/bin

(3).Resin

不是你的JSP攄相对路径,是JSP引擎执行q个JSP~译成SERVLET
的\径ؓ(f)?比如用新建文件法试File f = new File("a.htm");
q个a.htm在resin的安装目录下

(4).如何ȝ对\径哪Q?/p>

在Java文g中getResource或getResourceAsStream均可

例:(x)getClass().getResourceAsStream(filePath);//filePath可以?/filename",q里?代表web

发布根\径下WEB-INF/classes

默认使用该方法的路径是:(x)WEB-INF/classes。已l在Tomcat中测试?/p>

5.d文g时的相对路径Q避免硬~码和绝对\径的使用。(来自|络Q?br />5.1 采用Spring的DI机制获得文gQ避免硬~码?br />   参考下面的q接内容Q?br />   http://www.javajia.net/viewtopic.php?p=90213&
5.2 配置文g的读?br /> 参考下面的q接内容Q?br /> http://dev.csdn.net/develop/article/39/39681.shtm
5.3 通过虚拟路径或相对\径读取一个xml文gQ避免硬~码
 参考下面的q接内容Q?br /> http://club.gamvan.com/club/clubPage.jsp?iPage=1&tID=10708&ccID=8
 
6.Java中文件的常用操作Q复ӞUdQ删除,创徏{)Q来自网l)
 常用 java File 操作c?
 http://www.easydone.cn/014/200604022353065155.htm
 
 Java文g操作大全QJSP中)
 http://www.pconline.com.cn/pcedu/empolder/gj/java/0502/559401.html

 java文g操作详解QJava中文|)
 http://www.51cto.com/html/2005/1108/10947.htm

 JAVA 如何创徏\删除\修改\复制目录?qing)文?br /> http://www.gamvan.com/developer/java/2005/2/264.html

ȝQ?br /> 通过上面内容的用,可以解决在Web应用服务器端Q移动文Ӟ查找文gQ复?br /> 删除文g{操作,同时Ҏ(gu)务器的相对地址Q绝对地址概念更加清晰?br />参考URI,的RFC标准文挡。同时对Java.io.File. Java.net.URI.{内容了解透彻
对其他方面的理解可以更加深入和透彻?br />==================================================================================

参考资?
java/docs/

java.io.File
java.io.InputStream
java.io.OutputStream
java.io.FileInputStream
java.io.FileReader;
java.io.FileOutputStream
java.io.FileWriter;
java.net.URI
java.net.URL


l对路径与相对\径祥?br />http://www.webjx.com/htmldata/2005-02-26/1109430310.html

[『J道习(fn)l』]JSP和Servlet中的l对路径和相对\?br />http://w3china.org/blog/more.asp?name=pcthomas&id=9122&commentid=12376

JSP,Servlet,Class获得当前应用的相对\径和l对路径
http://cy.lzu.edu.cn/cy/club/clubPage.jsp?ccStyle=0&tID=886&ccID=77

如何获得当前文g路径
http://www.matrix.org.cn/resource/article/44/44113_java.html

通过Spring注入机制Q取得文?br />http://www.javajia.net/viewtopic.php?p=90213&

配置文g的读?
http://dev.csdn.net/develop/article/39/39681.shtm

d配置文g,通过虚拟路径或相对\径读取一个xml文gQ避免硬~码Q?
http://club.gamvan.com/club/clubPage.jsp?iPage=1&tID=10708&ccID=8

常用 java File 操作c?br />http://www.easydone.cn/014/200604022353065155.htm

Java文g操作大全
http://www.pconline.com.cn/pcedu/empolder/gj/java/0502/559401.html

Java文g操作详解
http://www.51cto.com/html/2005/1108/10947.htm




向东博客 2006-10-10 08:58 发表评论
]]>
java文g路径http://www.tkk7.com/meil/archive/2006/10/10/74165.html向东博客向东博客Tue, 10 Oct 2006 00:58:00 GMThttp://www.tkk7.com/meil/archive/2006/10/10/74165.htmlhttp://www.tkk7.com/meil/comments/74165.htmlhttp://www.tkk7.com/meil/archive/2006/10/10/74165.html#Feedback0http://www.tkk7.com/meil/comments/commentRss/74165.htmlhttp://www.tkk7.com/meil/services/trackbacks/74165.htmlSystem.out.println(System.getProperty("user.dir"));

如果你用q个Ҏ(gu)来杳看你JSP面Q可以发现它的\径很奇怪,其实它是JSP引擎路径。所以当你用
    new File(String path);
Ӟ如果用的是相对\径,得相对真实的当前\径,而不是Q何你惛_然的路径 ?br />当然对于q个Ҏ(gu)用”绝对\径“一般是不会(x)出错的。只是这PE序的灵zL就受到了限制。下面就是一个绝对\?的例子:(x)
    String xmlPath = "D:\\PublicFiles\\WCI\\navigation.xml";

Part 2
FileStream file = this.getClass().getClassLoader().getResourceAsStream(String xmlPath);
q个有点复杂Q我了解的也不多Q这里就说说现在我所了解的吧Q以后再补充Q?br />System.out.println(this.getClass().getClassLoader().getResource("/").getPath());
如此可以看到相对?”的根\径?br />对 ?FileStream fileStream = this.getClass().getClassLoader().getResourceAsStream(filePath);
q里的filePathg只能用相对\径,臛_我不知道用绝对\径怎么表示Q?br />下面取个相对路径的例子:(x)
    String filePath = "/../../Resources/XML/navigation.xml"; //表达规则和LINUX一栗?br />
System.out.println(this.getClass().getClassLoader().getResource(".").getPath());
System.out.println(this.getClass().getClassLoader().getResource("/").getPath());
System.out.println(this.getClass().getClassLoader().getResource("").getPath());
System.out.println(this.getClass().getClassLoader().getResource("..").getPath());
怿Q看q这四个路径l果应该知道在哪放|自q文g了,用什么样的语句能扑ֈ?br />
今天在写一个写JSPӞ到上面的文件\径的问题Q简单的了解下,怿其中定有不少的错误,希望你能提出q改正,我在此谢q了Q?br />


向东博客 2006-10-10 08:58 发表评论
]]>
JSP中的路径问题http://www.tkk7.com/meil/archive/2006/10/10/74166.html向东博客向东博客Tue, 10 Oct 2006 00:58:00 GMThttp://www.tkk7.com/meil/archive/2006/10/10/74166.htmlhttp://www.tkk7.com/meil/comments/74166.htmlhttp://www.tkk7.com/meil/archive/2006/10/10/74166.html#Feedback0http://www.tkk7.com/meil/comments/commentRss/74166.htmlhttp://www.tkk7.com/meil/services/trackbacks/74166.html 一Q?/font> 问题

    JSP 中究竟采用绝对\径还是采用相对\径随着所采用技术的来复杂,q个问题也变得越来越难以解决?/span>

Q) 采用相对路径遇到的问?/span>

l          相对路径固然比较灉|Q但如果惛_刉面内的代码却变得比较困难Q因Z同的面h不同的相对\径,复制后必MҎ(gu)一个连接的路径?/font>

l          如果面被多于一个的面所包含Q那么被包含面中的相对路径是不正的?/font>

l          如果采用 Struts ?/span> Action q回面Q那么由于页面\径与 Action 路径不同Q得浏览器无法正确解释面中的路径Q如面?/span> /pages/cust/cust.jsp Q图片所有目录ؓ(f) /images/title.gif Q这时在 /pages/cust/cust.jsp 中的所用的路径?/span> ?./../images/title.gif?/font> Q但是如果某一?/span> Action ?/span> Forward 指向q个 JSP 文gQ而这?/span> Action 的\径ؓ(f) /cust/manage.do Q那么页面内容中 ?./../images/title.gif?/font> ׃再指向正的路径了?/span>

解决以上问题g只有使用l对路径了?/font>

Q) 采用l对路径遇到的问?/span>

l          随着不同?/span> Web 应用发布方式Q绝对\径的g不同。如 Web 应用发布?/span> MyApp Q则路径 ?MyApp/images/title.gif?/font> 是正的Q但发布为另一应用时如 MyApp2 Q这个\径就不对了,也许q个情况比较?yu),但?/span> default 方式发布 Web 应用时以上绝对\径也不同Q?/span> ?images/title.gif?/font> ?/span>

二. 解决Ҏ(gu)

Q)   采用l对路径Q但Z解决不同部v方式的差别,在所有非 struts 标签的\径前?/span> ${pageContext.request.contextPath} Q如原\径ؓ(f)Q?/span>

?images/title.gif?/font> Q改?/span>

?{pageContext.request.contextPath}/images/title.gif?/font> ?/span>

代码 ?${pageContext.request.contextPath}?/font> 的作用是取出部v的应用程序名Q这样不如何部|Ԍ所用\径都是正的?/span>

~点Q?/span>

操作不便Q其他工h法正解?/span> ${pageContext.request.contextPath}

Q)   采用相对路径Q在每个 JSP 文g中加?/span> base 标签Q如Q?/span>

<base href="http://${header['host']}${pageContext.request.contextPath}/pages/cust/relation.jsp" />

q样所有的路径都可以用相对\径?/font>

~点Q?/span>

对于被包含的文g依然无效?/font>

    真正使用旉要灵zd用1Q和Q)Q写出更加健壮的代码?/span>



向东博客 2006-10-10 08:58 发表评论
]]>
JSP、Servlet中的相对路径和绝对\?/title><link>http://www.tkk7.com/meil/archive/2006/10/10/74167.html</link><dc:creator>向东博客</dc:creator><author>向东博客</author><pubDate>Tue, 10 Oct 2006 00:57:00 GMT</pubDate><guid>http://www.tkk7.com/meil/archive/2006/10/10/74167.html</guid><wfw:comment>http://www.tkk7.com/meil/comments/74167.html</wfw:comment><comments>http://www.tkk7.com/meil/archive/2006/10/10/74167.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.tkk7.com/meil/comments/commentRss/74167.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/meil/services/trackbacks/74167.html</trackback:ping><description><![CDATA[ <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">JSP</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">Servlet</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的l对路径和相对\径问题困C我好几天Q经q努力之后将光分心得和大家׃n?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <span style="mso-tab-count: 1"> <font face="Times New Roman">       </font> </span> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">前提Q假设你?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">Http</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">地址?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <a > <font face="Times New Roman" color="#000080">http://192.168.0.1/</font> </a> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">你的</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">web</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">应用?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">webapp</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q那么你?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">web</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">应用</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">URL</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <a > <font face="Times New Roman" color="#000080">http://192.168.0.1/webapp/</font> </a> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman"> <span style="mso-tab-count: 1">       </span>web</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">应用的目录结构:(x)</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman"> <span style="mso-tab-count: 1">       </span>webapp/<o:p></o:p></font> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman"> <span style="mso-tab-count: 2">              </span>web-inf/<o:p></o:p></font> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman"> <span style="mso-tab-count: 2">              </span> <span style="mso-spacerun: yes">   </span>classes/<o:p></o:p></font> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman"> <span style="mso-tab-count: 3">                     </span>lib/<o:p></o:p></font> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman"> <span style="mso-tab-count: 3">                     </span>web.xml<o:p></o:p></font> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman"> <span style="mso-tab-count: 4">                            </span> <span style="mso-spacerun: yes">  </span><servlet-mapping><o:p></o:p></font> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman"> <span style="mso-spacerun: yes">    </span> <span style="mso-tab-count: 4">                           </span><servlet-name>handleservlet</servlet-name><o:p></o:p></font> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 60pt; TEXT-INDENT: -60pt; mso-char-indent-count: -5.0"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman"> <span style="mso-spacerun: yes">    </span> <span style="mso-tab-count: 4">                           </span><url-pattern>/handleservlet</url-pattern></font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">此映是相对于当?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">web</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">应用?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman"> <span style="mso-spacerun: yes">  </span> <span style="mso-tab-count: 4">                        </span> <span style="mso-spacerun: yes">   </span></servlet-mapping><o:p></o:p></font> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman"> <span style="mso-tab-count: 2">              </span>user/<o:p></o:p></font> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 63pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">a.jsp<o:p></o:p></font> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 63pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">b.jsp<o:p></o:p></font> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman"> <span style="mso-tab-count: 2">              </span>images/<o:p></o:p></font> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman"> <span style="mso-tab-count: 2">              </span>css/<o:p></o:p></font> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman"> <span style="mso-tab-count: 2">              </span>js/<o:p></o:p></font> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman"> <span style="mso-tab-count: 2">              </span> <o:p> </o:p> </font> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <span style="mso-tab-count: 1"> <font face="Times New Roman">       </font> </span> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所有相对\径都是由?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">/</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">”开头的。如Q?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">/image/a.gif</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">/user/main.jsp</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q大家知道在</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">html</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的相对路径是这L(fng)Q?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <span style="mso-tab-count: 1"> <font face="Times New Roman">       </font> </span> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">有个</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">html</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文gQ?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">a.html</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q其中有</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman"><link href="one.css" rel="stylesheet" type="text/css"></font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q其?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">href</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">属性表C引用的</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">css</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文g的\径?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">one.css</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q表C?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">one.css</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">a.hmtl</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">处于同一个目?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">user/one.css</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q表C?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">one.css</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">处于</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">a.html</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所在目录的子目?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">user</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">../one.css</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q表C?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">one.css</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">位于</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">a.hmtl</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">上一U目录下Q?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">../../one.css</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q表C?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">one.css</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">位于</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">a.hmtl</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">上一U目录的上一U目录下Q?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">./</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q表C和</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">a.hmtl</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">同一目录</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt"> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我们UCq相对\径ؓ(f)</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">html</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">相对路径</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1; tab-stops: list 18.0pt"> <span lang="EN-US" style="FONT-SIZE: 12pt; mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore"> <font face="Times New Roman">1?/font> </span> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">服务器端的地址</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: 21pt"> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">服务器端的相对地址指的是相对于你的</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">web</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">应用的地址Q这个地址是在服务器端解析的(不同?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">html</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">javascript</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的相对地址Q他们是由客L(fng)览器解析的Q也是说这时候在</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">jsp</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">servlet</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的相对地址应该是相对于你的</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">web</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">应用Q即相对?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <a > <font face="Times New Roman" color="#000080">http://192.168.0.1/webapp/</font> </a> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: 21pt"> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">其用到的地方有:(x)</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: 21pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">forwarder</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">servlet</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">request.getRequestDispatcher(address);</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">q个</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">address</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">是在服务器端解析的,所以,你要</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">forwarder</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">a.jsp</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">应该q么写:(x)</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">request.getRequestDispatcher(?user/a.jsp?</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">q个</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">/</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">相对于当前的</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">web</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">应用</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">webapp</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q其l对地址是Q?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <a > <font face="Times New Roman" color="#000080">http://192.168.0.1/webapp/user/a.jsp</font> </a> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: 21pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">sendRedirect</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q在</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">jsp</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman"><%response.sendRedirect("/rtccp/user/a.jsp");%><o:p></o:p></font> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1; tab-stops: list 18.0pt"> <span lang="EN-US" style="FONT-SIZE: 12pt; mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore"> <font face="Times New Roman">2?/font> </span> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">客户端的地址</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: 21pt"> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所有的</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">html</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的相对地址都是相对?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <a > <font face="Times New Roman" color="#000080">http://192.168.0.1/</font> </a> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的,而不?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <a > <font face="Times New Roman" color="#000080">http://192.168.0.1/webapp/</font> </a> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: 21pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">Html</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">form</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表单?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">action</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">属性的地址应该是相对于</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <a > <font face="Times New Roman" color="#000080">http://192.168.0.1/</font> </a> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的,所以,如果提交?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">a.jsp</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为:(x)</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">action</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">?webapp/user/a.jsp?/font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q提交到</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">servlet</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">action</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Q?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">?webapp/handleservlet?o:p></o:p></font> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: 21pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">Javascript</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">也是在客L(fng)解析的,所以其相对路径?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">form</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">表单一栗?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo1; tab-stops: list 18.0pt"> <span lang="EN-US" style="FONT-SIZE: 12pt; mso-fareast-font-family: 'Times New Roman'"> <span style="mso-list: Ignore"> <font face="Times New Roman">3?/font> </span> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">站点根目录和</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">css</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">路径问题</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">我们U类DL(fng)相对路径</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">/webapp/?</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">为相对于站点根目录的相对路径?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">当在</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">jsp</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中引?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">css</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Ӟ如果其相对\径相对于当前</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">jsp</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文g的,而在一个和q个</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">jsp</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的\径不一L(fng)</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">servlet</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">forwarder</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">q个</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">jsp</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">Ӟ׃(x)发现q个</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">css</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">样式Ҏ(gu)没有起作用。这是因为在</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">servlet</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中{发时</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">css</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的\径就是相对于q个</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">servlet</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的相对\径而非</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">jsp</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的\径了。所以这时候不能在</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">jsp</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中用q样的\径:(x)</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman"><link href="one.css" rel="stylesheet" type="text/css"></font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">或?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman"><link href="../../one.css" rel="stylesheet" type="text/css"></font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">cM</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">href="one.css"</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">../../one.css</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">html</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">相对路径是相对于引用q个</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">css</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的文件的相对路径。而在</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">servlet</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中{发时是相对于这?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">servlet</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的相对\径了Q因?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">jsp</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">路径?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">servlet</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">路径是不一L(fng)Q所以这L(fng)引用肯定是出错的?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">所以这个时候,要用站点根目录,是相对?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <a > <font face="Times New Roman" color="#000080">http://192.168.0.1/</font> </a> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的目录,以?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">/</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">”开头?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">因此上述错误应更正ؓ(f)</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">href=?webapp/one.css?/font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">cM的站Ҏ(gu)目录的相对目录。这样在</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">servlet</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">转发后和</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">jsp</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中都是相对于站点根目录的相对路径Q就能正用所定义?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <font face="Times New Roman">css</font> </span> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">样式了?/span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> <font face="Times New Roman"> </font> </o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 21pt"> <span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">说了q么多,不知道你了解没,有什么问题留aQ大家一块交!</span> <span lang="EN-US" style="FONT-SIZE: 12pt"> <o:p> </o:p> </span> </p> <img src ="http://www.tkk7.com/meil/aggbug/74167.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/meil/" target="_blank">向东博客</a> 2006-10-10 08:57 <a href="http://www.tkk7.com/meil/archive/2006/10/10/74167.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JAVA字符?/title><link>http://www.tkk7.com/meil/archive/2006/10/10/74209.html</link><dc:creator>向东博客</dc:creator><author>向东博客</author><pubDate>Tue, 10 Oct 2006 00:56:00 GMT</pubDate><guid>http://www.tkk7.com/meil/archive/2006/10/10/74209.html</guid><wfw:comment>http://www.tkk7.com/meil/comments/74209.html</wfw:comment><comments>http://www.tkk7.com/meil/archive/2006/10/10/74209.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/meil/comments/commentRss/74209.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/meil/services/trackbacks/74209.html</trackback:ping><description><![CDATA[1. 概述 <br /><br />本文主要包括以下几个斚wQ编码基本知识,javaQ系lYӞurlQ工兯Y件等?<br /><br />在下面的描述中,以"中文"两个字ؓ(f)例,l查表可以知道其GB2312~码?d6d0 cec4"QUnicode~码?4e2d 6587"QUTF~码是"e4b8ad e69687"。注意,q两个字没有iso8859-1~码Q但可以用iso8859-1~码?表示"?<br /><br />2. ~码基本知识 <br /><br />最早的~码是iso8859-1Q和ascii~码怼。但Z方便表示各种各样的语aQ逐渐出现了很多标准编码,重要的有如下几个?<br /><br />2.1. iso8859-1 <br /><br />属于单字节编码,最多能表示的字W范围是0-255Q应用于英文pd。比如,字母a的编码ؓ(f)0x61=97?<br /><br />很明显,iso8859-1~码表示的字W范围很H,无法表示中文字符。但是,׃是单字节~码Q和计算机最基础的表C单位一_(d)所以很多时候,仍旧使用iso8859-1~码来表C。而且在很多协议上Q默认用该~码。比如,虽然"中文"两个字不存在iso8859-1~码Q以gb2312~码ZQ应该是"d6d0 cec4"两个字符Q用iso8859-1~码的时候则它拆开?个字节来表示Q?d6 d0 ce c4"Q事实上Q在q行存储的时候,也是以字节ؓ(f)单位处理的)。而如果是UTF~码Q则?个字?e4 b8 ad e6 96 87"。很明显Q这U表C方法还需要以另一U编码ؓ(f)基础?<br /><br />2.2. GB2312/GBK <br /><br />q就是汉子的国标码,专门用来表示汉字Q是双字节编码,而英文字母和iso8859-1一_(d)兼容iso8859-1~码Q。其中gbk~码能够用来同时表示J体字和体字Q而gb2312只能表示体字Qgbk是兼容gb2312~码的?<br /><br />2.3. unicode <br /><br />q是最l一的编码,可以用来表示所有语a的字W,而且是定长双字节Q也有四字节的)~码Q包括英文字母在内。所以可以说它是不兼容iso8859-1~码的,也不兼容M~码。不q,相对于iso8859-1~码来说Quniocode~码只是在前面增加了一?字节Q比如字母a?00 61"?<br /><br />需要说明的是,定长~码便于计算机处理(注意GB2312/GBK不是定长~码Q,而unicode又可以用来表C所有字W,所以在很多软g内部是用unicode~码来处理的Q比如java?<br /><br />2.4. UTF <br /><br />考虑到unicode~码不兼容iso8859-1~码Q而且Ҏ(gu)占用更多的空_(d)(x)因ؓ(f)对于英文字母Qunicode也需要两个字节来表示。所以unicode不便于传输和存储。因此而生了utf~码Qutf~码兼容iso8859-1~码Q同时也可以用来表示所有语a的字W,不过Qutf~码是不定长~码Q每一个字W的长度?-6个字节不{。另外,utf~码自带单的校验功能。一般来Ԍ英文字母都是用一个字节表C,而汉字用三个字节?<br /><br />注意Q虽然说utf是ؓ(f)了用更的I间而用的Q但那只是相对于unicode~码来说Q如果已l知道是汉字Q则使用GB2312/GBK无疑是最节省的。不q另一斚wQ值得说明的是Q虽然utf~码Ҏ(gu)字?个字节,但即使对于汉字网,utf~码也会(x)比unicode~码节省Q因为网中包含了很多的英文字符?<br /><br />3. java对字W的处理 <br /><br />在java应用软g中,?x)有多处涉?qing)到字W集~码Q有些地斚w要进行正的讄Q有些地斚w要进行一定程度的处理?<br /><br />3.1. getBytes(charset) <br /><br />q是java字符串处理的一个标准函敎ͼ其作用是字W串所表示的字W按照charset~码Qƈ以字节方式表C。注意字W串在java内存中L按unicode~码存储的。比?中文"Q正常情况下Q即没有错误的时候)存储?4e2d 6587"Q如果charset?gbk"Q则被编码ؓ(f)"d6d0 cec4"Q然后返回字?d6 d0 ce c4"。如果charset?utf8"则最后是"e4 b8 ad e6 96 87"。如果是"iso8859-1"Q则׃无法~码Q最后返?"3f 3f"Q两个问P?<br /><br />3.2. new String(charset) <br /><br />q是java字符串处理的另一个标准函敎ͼ和上一个函数的作用相反Q将字节数组按照charset~码q行l合识别Q最后{换ؓ(f)unicode存储。参考上qgetBytes的例子,"gbk" ?utf8"都可以得出正的l果"4e2d 6587"Q但iso8859-1最后变成了"003f 003f"Q两个问P?<br /><br />因ؓ(f)utf8可以用来表示/~码所有字W,所以new String( str.getBytes( "utf8" ), "utf8" ) === strQ即完全可逆?<br /><br />3.3. setCharacterEncoding() <br /><br />该函数用来设|httph或者相应的~码?<br /><br />对于requestQ是指提交内容的~码Q指定后可以通过getParameter()则直接获得正的字符Ԍ如果不指定,则默认用iso8859-1~码Q需要进一步处理。参见下q?表单输入"。值得注意的是在执行setCharacterEncoding()之前Q不能执行Q何getParameter()。java doc上说明:(x)This method must be called prior to reading request parameters or reading input using getReader()。而且Q该指定只对POSTҎ(gu)有效Q对GETҎ(gu)无效。分析原因,应该是在执行W一个getParameter()的时候,java会(x)按照~码分析所有的提交内容Q而后l的getParameter()不再q行分析Q所以setCharacterEncoding()无效。而对于GETҎ(gu)提交表单是,提交的内容在URL中,一开始就已经按照~码分析所有的提交内容QsetCharacterEncoding()自然无效?<br /><br />对于responseQ则是指定输出内容的~码Q同Ӟ该设|会(x)传递给览器,告诉览器输出内Ҏ(gu)采用的编码?<br /><br />3.4. 处理q程 <br /><br />下面分析两个有代表性的例子Q说明java对编码有关问题的处理Ҏ(gu)?<br /><br />3.4.1. 表单输入 <br /><br />User input *(gbk:d6d0 cec4) browser *(gbk:d6d0 cec4) web server iso8859-1(00d6 00d 000ce 00c4) classQ需要在class中进行处理:(x)getbytes("iso8859-1")为d6 d0 ce c4Qnew String("gbk")为d6d0 cec4Q内存中以unicode~码则ؓ(f)4e2d 6587?<br /><br />l 用户输入的编码方式和面指定的编码有养I也和用户的操作系l有养I所以是不确定的Q上例以gbkZ?<br /><br />l 从browser到web serverQ可以在表单中指定提交内Ҏ(gu)使用的字W集Q否则会(x)使用面指定的编码。而如果在url中直接用?的方式输入参敎ͼ则其~码往往是操作系l本w的~码Q因时和面无关。上qC旧以gbk~码Z?<br /><br />l Web server接收到的是字节流Q默认时QgetParameterQ会(x)以iso8859-1~码处理之,l果是不正确的,所以需要进行处理。但如果预先讄了编码(通过request. setCharacterEncoding ()Q,则能够直接获取到正确的结果?<br /><br />l 在页面中指定~码是个好习(fn)惯,否则可能失去控制Q无法指定正的~码?<br /><br />3.4.2. 文g~译 <br /><br />假设文g是gbk~码保存的,而编译有两种~码选择Qgbk或者iso8859-1Q前者是中文windows的默认编码,后者是linux的默认编码,当然也可以在~译时指定编码?<br /><br />Jsp *(gbk:d6d0 cec4) java file *(gbk:d6d0 cec4) compiler read uincode(gbk: 4e2d 6587; iso8859-1: 00d6 00d 000ce 00c4) compiler write utf(gbk: e4b8ad e69687; iso8859-1: *) compiled file unicode(gbk: 4e2d 6587; iso8859-1: 00d6 00d 000ce 00c4) class。所以用gbk~码保存Q而用iso8859-1~译的结果是不正的?<br /><br />class unicode(4e2d 6587) system.out / jsp.out gbk(d6d0 cec4) os console / browser?<br /><br />l 文g可以以多U编码方式保存,中文windows下,默认为ansi/gbk?<br /><br />l ~译器读取文件时Q需要得到文件的~码Q如果未指定Q则使用pȝ默认~码。一般class文gQ是以系l默认编码保存的Q所以编译不?x)出问题Q但对于jsp文gQ如果在中文windows下编辑保存,而部|在英文linux下运?~译Q则?x)出现问题。所以需要在jsp文g中用pageEncoding指定~码?<br /><br />l Java~译的时候会(x)转换成统一的unicode~码处理Q最后保存的时候再转换为utf~码?<br /><br />l 当系l输出字W的时候,?x)按指定~码输出Q对于中文windows下,System.out用gbk~码Q而对于responseQ浏览器Q,则用jsp文g头指定的contentTypeQ或者可以直接ؓ(f)response指定~码。同Ӟ?x)告诉browser|页的编码。如果未指定Q则?x)用iso8859-1~码。对于中文,应该为browser指定输出字符串的~码?<br /><br />l browser昄|页的时候,首先使用response中指定的~码Qjsp文g头指定的contentType最l也反映在response上)Q如果未指定Q则?x)用网中metaҎ(gu)定中的contentType?<br /><br />3.5. 几处讄 <br /><br />对于web应用E序Q和~码有关的设|或者函数如下?<br /><br />3.5.1. jsp~译 <br /><br />指定文g的存储编码,很明显,该设|应该置于文件的开头。例如:(x)<%@page pageEncoding="GBK"%>。另外,对于一般class文gQ可以在~译的时候指定编码?<br /><br />3.5.2. jsp输出 <br /><br />指定文g输出到browser是用的~码Q该讄也应该置于文件的开头。例如:(x)<%@ page contentType="text/html; charset= GBK" %>。该讄和response.setCharacterEncoding("GBK"){效?<br /><br />3.5.3. meta讄 <br /><br />指定|页使用的编码,该设|对静态网尤其有作用。因为静态网|法采用jsp的设|,而且也无法执行response.setCharacterEncoding()。例如:(x) <br /><br />如果同时采用了jsp输出和meta讄两种~码指定方式Q则jsp指定的优先。因为jsp指定的直接体现在response中?<br /><br />需要注意的是,apache有一个设|可以给无编码指定的|页指定~码Q该指定{同于jsp的编码指定方式,所以会(x)覆盖静态网中的meta指定。所以有人徏议关闭该讄?<br /><br />3.5.4. form讄 <br /><br />当浏览器提交表单的时候,可以指定相应的编码。例如:(x) <form accept-charset="gb2312">。一般不必不使用该设|,览器会(x)直接使用|页的编码?<br /><br />4. pȝ软g <br /><br />下面讨论几个相关的系lY件?<br /><br />4.1. mysql数据?<br /><br />很明显,要支持多语言Q应该将数据库的~码讄成utf或者unicodeQ而utf更适合与存储。但是,如果中文数据中包含的英文字母很少Q其实unicode更ؓ(f)适合?<br /><br />数据库的~码可以通过mysql的配|文件设|,例如default-character-set=utf8。还可以在数据库链接URL中设|,例如Q?useUnicode=true&characterEncoding=UTF-8。注意这两者应该保持一_(d)在新的sql版本里,在数据库链接URL里可以不q行讄Q但也不能是错误的设|?<br /><br />4.2. apache <br /><br />appache和编码有关的配置在httpd.conf中,例如AddDefaultCharset UTF-8。如前所qͼ该功能会(x)所有静态页面的~码讄为UTF-8Q最好关闭该功能?<br /><br />另外Qapacheq有单独的模块来处理|页响应_(d)其中也可能对~码q行讄?<br /><br />4.3. linux默认~码 <br /><br />q里所说的linux默认~码Q是指运行时的环境变量。两个重要的环境变量是LC_ALL和LANGQ默认编码会(x)影响到java URLEncode的行为,下面有描q?<br /><br />都设|ؓ(f)"zh_CN.UTF-8"?<br /><br />4.4. 其它 <br /><br />Z支持中文文g名,linux在加载磁盘时应该指定字符集,例如Qmount /dev/hda5 /mnt/hda5/ -t ntfs -o iocharset=gb2312?<br /><br />另外Q如前所qͼ使用GETҎ(gu)提交的信息不支持request.setCharacterEncoding()Q但可以通过tomcat的配|文件指定字W集Q在tomcat的server.xml文g中,形如Q?connector ...="" uriencoding="GBK" />。这U方法将l一讄所有请求,而不能针对具体页面进行设|,也不一定和browser使用的编码相同,所以有时候ƈ不是所期望的?<br /><br />5. URL地址 <br /><br />URL地址中含有中文字W是很麻烦的Q前面描q过使用GETҎ(gu)提交表单的情况,使用GETҎ(gu)Ӟ参数是包含在URL中?<br /><br />5.1. URL~码 <br /><br />对于URL中的一些特D字W,览器会(x)自动q行~码。这些字W除?/?&"{外Q还包括unicode字符Q比如汉子。这时的~码比较Ҏ(gu)?<br /><br />IE有一个选项"L使用UTF-8发送URL"Q当该选项有效ӞIE会(x)对特D字W进行UTF-8~码Q同时进行URL~码。如果改选项无效Q则使用默认~码"GBK"Qƈ且不q行URL~码。但是,对于URL后面的参敎ͼ则L不进行编码,相当于UTF-8选项无效。比?中文.html?a=中文"Q当UTF-8选项有效Ӟ发送链?%e4%b8%ad%e6%96%87.html?a=x4ex2dx65x87"Q而UTF-8选项无效Ӟ发送链?x4ex2dx65x87.html?a=x4ex2dx65x87"。注意后者前面的"中文"两个字只?个字节,而前者却?8个字节,q主要时URL~码的原因?<br /><br />当web serverQtomcatQ接收到该链接时Q将?x)进行URL解码Q即L"%"Q同时按照ISO8859-1~码Q上面已l描qͼ可以使用URLEncoding来设|成其它~码Q识别。上qC子的l果分别?ue4ub8uadue6u96u87.html?a=u4eu2du65u87"?u4eu2du65u87.html?a=u4eu2du65u87"Q注意前者前面的"中文"两个字恢复成?个字W。这里用"u"Q表C是unicode?<br /><br />所以,׃客户端设|的不同Q相同的链接Q在服务器上得到了不同结果。这个问题不h都遇刎ͼ却没有很好的解决办法。所以有的网站会(x)用户试关闭UTF-8选项。不q,下面?x)描qC个更好的处理办法?<br /><br />5.2. rewrite <br /><br />熟?zhn)的h都知道,apache有一个功能强大的rewrite模块Q这里不描述其功能。需要说明的是该模块?x)自动将URL解码Q去?Q,卛_成上qweb serverQtomcatQ的部分功能。有相关文档介绍说可以用[NE]参数来关闭该功能Q但我试验ƈ未成功,可能是因为版本(我用的是apache 2.0.54Q问题。另外,当参C含有"?& "{符L(fng)时候,该功能将Dpȝ得不到正常结果?<br /><br />rewrite本ng完全是采用字节处理的方式Q而不考虑字符串的~码Q所以不?x)带来编码问题?<br /><br />5.3. URLEncode.encode() <br /><br />q是Java本n提供对的URL~码函数Q完成的工作和上qUTF-8选项有效时浏览器所做的工作怼。值得说明的是Qjava已经不赞成不指定~码来用该Ҏ(gu)QdeprecatedQ。应该在使用的时候增加编码指定?<br /><br />当不指定~码的时候,该方法用系l默认编码,q会(x)D软gq行l果得不定。比如对?中文"Q当pȝ默认~码?gb2312"Ӟl果?%4e%2d%65%87"Q而默认编码ؓ(f)"UTF-8"Q结果却?%e4%b8%ad%e6%96%87"Q后l程序将难以处理。另外,q儿说的pȝ默认~码是由q行tomcat时的环境变量LC_ALL和LANG{决定的Q曾l出现过tomcat重启后就出现q的问题,最后才郁闷的发现是因ؓ(f)修改修改了这两个环境变量?<br /><br />l一指定?UTF-8"~码Q可能需要修改相应的E序?<br /><br />5.4. 一个解x?<br /><br />上面说vq,因ؓ(f)览器设|的不同Q对于同一个链接,web server收到的是不同内容Q而Y件系l有无法知道q中间的区别Q所以这一协议目前q存在缺陗?<br /><br />针对具体问题Q不应该侥幸认ؓ(f)所有客L(fng)IE讄都是UTF-8有效的,也不应该_暴的徏议用户修改IE讄Q要知道Q用户不可能去记住每一个web server的设|。所以,接下来的解决办法只能是让自qE序多一Ҏ(gu)能:(x)Ҏ(gu)内容来分析编码是否UTF-8?<br /><br />比较q运的是UTF-8~码相当有规律,所以可以通过分析传输q来的链接内容,来判断是否是正确的UTF-8字符Q如果是Q则以UTF-8处理之,如果不是Q则使用客户默认~码Q比?GBK"Q,下面是一个判断是否UTF-8的例子,如果你了解相应规律,容易理解?<br /><br />public static boolean isValidUtf8(byte[] b,int aMaxCount){ <br /><br />int lLen=b.length,lCharCount=0; <br /><br />for(int i=0;i<llen &&="" lcharcount<amaxcount;++lcharcount){=""><br /><br />byte lByte=b[i++];//to fast operation, ++ now, ready for the following for(;;) <br /><br />if(lByte>=0) continue;//>=0 is normal ascii <br /><br />if(lByte<(byte)0xc0 || lByte>(byte)0xfd) return false; <br /><br />int lCount=lByte>(byte)0xfc?5:lByte>(byte)0xf8?4 <br /><br />:lByte>(byte)0xf0?3:lByte>(byte)0xe0?2:1; <br /><br />if(i+lCount>lLen) return false; <br /><br />for(int j=0;j<lcount;++j,++i) if(b[i]="">=(byte)0xc0) return false; <br /><br />} <br /><br />return true; <br /><br />} <br /><br />相应圎ͼ一个用上q方法的例子如下Q?<br /><br />public static String getUrlParam(String aStr,String aDefaultCharset) <br /><br />throws UnsupportedEncodingException{ <br /><br />if(aStr==null) return null; <br /><br />byte[] lBytes=aStr.getBytes("ISO-8859-1"); <br /><br />return new String(lBytes,StringUtil.isValidUtf8(lBytes)?"utf8":aDefaultCharset); <br /><br />} <br /><br />不过Q该Ҏ(gu)也存在缺P如下两方面:(x) <br /><br />l 没有包括对用户默认编码的识别Q这可以Ҏ(gu)h信息的语a来判断,但不一定正,因ؓ(f)我们有时候也?x)输入一些韩文,或者其他文字?<br /><br />l 可能?x)错误判断UTF-8字符Q一个例子是"学习(fn)"两个字,其GBK~码? xd1xa7xcfxb0"Q如果用上qisValidUtf8Ҏ(gu)判断Q将q回true。可以考虑使用更严格的判断Ҏ(gu)Q不q估计效果不大?<br /><br />有一个例子可以证明google也遇C上述问题Q而且也采用了和上q相似的处理Ҏ(gu)Q比如,如果在地址栏中输入"http://www.google.com/search?hl=zh-CN&newwindow=1&q=学习(fn)"Qgoogle无法正识别,而其他汉字一般能够正常识别?<br /><br />最后,应该补充说明一下,如果不用rewrite规则Q或者通过表单提交数据Q其实ƈ不一定会(x)遇到上述问题Q因时可以在提交数据时指定希望的~码。另外,中文文g名确实会(x)带来问题Q应该}慎用?<br /><br />6. 其它 <br /><br />下面描述一些和~码有关的其他问题?<br /><br />6.1. SecureCRT <br /><br />除了览器和控制C~码有关外,一些客L(fng)也很有关pR比如在使用SecureCRTq接linuxӞ应该让SecureCRT的显C编码(不同的sessionQ可以有不同的编码设|)和linux的编码环境变量保持一致。否则看到的一些帮助信息,可能是q?<br /><br />另外Qmysql有自q~码讄Q也应该保持和SecureCRT的显C编码一致。否则通过SecureCRT执行sql语句的时候,可能无法处理中文字符Q查询结果也?x)出Cؕ码?<br /><br />对于Utf-8文gQ很多编辑器Q比如记事本Q会(x)在文件开头增加三个不可见的标志字节,如果作ؓ(f)mysql的输入文Ӟ则必要Lq三个字W。(用linux的vi保存可以Lq三个字W)。一个有的现象是,在中文windows下,创徏一个新txt文gQ用C本打开Q输?q?两个字,保存Q再打开Q你?x)发C个字没了Q只留下一个小黑点?<br /><br />6.2. qo(h)?<br /><br />如果需要统一讄~码Q则通过filterq行讄是个不错的选择。在filter class中,可以l一为需要的h或者回应设|编码。参加上qsetCharacterEncoding()。这个类apache已经l出了可以直接用的例子SetCharacterEncodingFilter?<br /><br />6.3. POST和GET <br /><br />很明显,以POST提交信息ӞURL有更好的可读性,而且可以方便的用setCharacterEncoding()来处理字W集问题。但GETҎ(gu)形成的URL能够更容易表辄늚实际内容Q也能够用于收藏?<br /><br />从统一的角度考虑问题Q徏议采用GETҎ(gu)Q这要求在程序中获得参数是进行特D处理,而无法用setCharacterEncoding()的便利,如果不考虑rewriteQ就不存在IE的UTF-8问题Q可以考虑通过讄URIEncoding来方便获取URL中的参数?<br /><br />6.4. J体~码转换 <br /><br />GBK同时包含体和J体~码Q也是说同一个字Q由于编码不同,在GBK~码下属于两个字。有时候,Z正确取得完整的结果,应该繁体和体进行统一。可以考虑UTF、GBK中的所有繁体字Q{换ؓ(f)相应的简体字QBIG5~码的数据,也应该{化成相应的简体字。当Ӟ仍旧以UTF~码存储?<br /><br />例如Q对?语言 ?a"Q用UTF表示?xE8xAFxADxE8xA8x80 xE8xAAx9ExE8xA8x80"Q进行简J体~码转换后应该是两个相同?"xE8xAFxADxE8xA8x80>"?<br /></lcount;++j,++i)></llen></form><img src ="http://www.tkk7.com/meil/aggbug/74209.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/meil/" target="_blank">向东博客</a> 2006-10-10 08:56 <a href="http://www.tkk7.com/meil/archive/2006/10/10/74209.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>лǵվܻԴȤ</p> <a href="http://www.tkk7.com/" title="亚洲av成人片在线观看">亚洲av成人片在线观看</a> <div class="friend-links"> </div> </div> </footer> վ֩ģ壺 <a href="http://www-60060.com" target="_blank">ѹۿɫƵվbd</a>| <a href="http://wxxwy.com" target="_blank">˳ɴƬ߹ۿŵӰ</a>| <a href="http://maopiandao163.com" target="_blank">޹Ʒһ</a>| <a href="http://kmp77.com" target="_blank">þü޾Ʒ?V</a>| <a href="http://hqshimo.com" target="_blank">Ļþһ</a>| <a href="http://a8g8.com" target="_blank">˾Ʒҹ侫պ</a>| <a href="http://42329c.com" target="_blank">ҹþþþþþþõӰ</a>| <a href="http://fz166.com" target="_blank">ۺAV߲</a>| <a href="http://cjfuli.com" target="_blank">ĻþþƷAPP </a>| <a href="http://715686.com" target="_blank">Ƶ߹ۿѲӰԺ</a>| <a href="http://wwwtoutoulu.com" target="_blank">99aƷ</a>| <a href="http://smalody.com" target="_blank">ƷһëƬ</a>| <a href="http://btztjxc.com" target="_blank">ɫһëƬ</a>| <a href="http://wanguoshan.com" target="_blank">õɫƵȫ</a>| <a href="http://cndianxian.com" target="_blank">91Ʒѹ</a>| <a href="http://xjscr.com" target="_blank">޵һҳۺͼƬ</a>| <a href="http://zzjiji.com" target="_blank">mm1313޹ƷŮ</a>| <a href="http://xyxpx.com" target="_blank">þþþ޾Ʒ˵</a>| <a href="http://fsszx888.com" target="_blank">鶹ۺ뾫Ʒ</a>| <a href="http://3344by.com" target="_blank">պһ</a>| <a href="http://0755szyxcm.com" target="_blank">AVר4SE</a>| <a href="http://adcadm.com" target="_blank">Ƶһ</a>| <a href="http://3838dydy.com" target="_blank">޹ŮƷþþþ</a>| <a href="http://cjfuli.com" target="_blank"></a>| <a href="http://sdshfengji.com" target="_blank">лGAYƬվWWW</a>| <a href="http://8654123.com" target="_blank">þ99þóѲ</a>| <a href="http://8884493.com" target="_blank">ҹվ߹ۿۿ</a>| <a href="http://34jjjj.com" target="_blank">ҹƵѹۿ</a>| <a href="http://www79909c.com" target="_blank">ձXXXѿ</a>| <a href="http://www664660a.com" target="_blank">߹ۿİ</a>| <a href="http://www66susu.com" target="_blank">պVAĻ </a>| <a href="http://ettedia.com" target="_blank">ҹҹƵ</a>| <a href="http://km9c.com" target="_blank">ÿ߹ۿapp</a>| <a href="http://3c3w.com" target="_blank">պŷAVҹҹ</a>| <a href="http://www137av.com" target="_blank">4480yy˽ӰԺ</a>| <a href="http://www-282555.com" target="_blank">ɫ͵͵ۺav78</a>| <a href="http://345504.com" target="_blank">һһһëƬëƬ</a>| <a href="http://kmc19.com" target="_blank">99߹ۿƵ</a>| <a href="http://w6626.com" target="_blank">ѵһƬվ</a>| <a href="http://xianliwang.com" target="_blank">㽶AVվ߹ۿ</a>| <a href="http://g8zb.com" target="_blank">޾Ʒŷ޾Ʒ</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>