发布于 2016-08-15 23:15:52 | 243 次阅读 | 评论: 1 | 来源: 网友投递

这里有新鲜出炉的JSP教程,程序狗速度看过来!

JSP JAVA公司的WEB开发编程语言

JSP全名为Java Server Pages - java服务器页面是由Sun Microsystems公司倡导、许多公司参与一起建立的一种动态网页技术标准。JSP技术有点类似ASP技术,它是在传统的网页HTML(标准通用标记语言的子集)文件(*.htm,*.html)中插入Java程序段(Scriptlet)和JSP标记(tag),从而形成JSP文件,后缀名为(*.jsp)。


javascript通过url向jsp页面传递中文参数乱码,一直都是从事jsp开发者比较烦心的是,于是本文介绍了一些解决方法,感兴趣的朋友可以了解下
2013-1-16 10:35:49 org.apache.tomcat.util.http.Parameters processParameters
警告: Parameters: Character decoding failed. Parameter 'id' with value '%u8BA2%u5355' has been ignored. Note that the name and value quoted here may corrupted due to the failed decoding. Use debug level logging to see the original, non-corrupted values.
Enter Servlet Get Method..
OK:
2013-1-16 10:35:49 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet suggest threw exception
java.lang.NullPointerException
at com.ont.demo.suggest.doGet(suggest.java:25)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)

解决方法:在传递参数前将中文参数进行两次编码,jsp页面获取参数后对中文参数进行一次解码,中文参数就不会变为乱码了!

参考例子
 
<%@ page language="java" contentType="text/html; charset=UTF-8" 
pageEncoding="UTF-8"%> 
<%@ page import="java.net.*" %> 
<% 
String str0=""; 
String str1=""; 
if(request.getParameter("param0")!=null){ 
str0=request.getParameter("param0");//直接获取中文参数 
} 
try{ 
if(request.getParameter("param1")!=null){ 
str1=URLDecoder.decode(request.getParameter("param1"),"utf-8");//对中文参数进行解码 
} 
}catch(Exception e){ 
e.printStackTrace(); 
} 
%> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<script type="text/javascript"> 
var str="你好"; 
function test0(){ 
window.location="Test.jsp?param0="+str;//直接传递中文参数 
} 
function test1(){ 
window.location="Test.jsp?param1="+encodeURI(encodeURI(str));//对中文参数进行双层编码后再传递 
} 
</script> 
</head> 
<body> 
<input value=<%=str0 %>> 
<input type="button" value="乱码" onclick="test0()"><br> 
<input value=<%=str1 %>> 
<input type="button" value="正常" onclick="test1()"> 
</body> 
</html> 


最新网友评论  共有(1)条评论 发布评论 返回顶部
dxq 发布于2016-08-31 23:16:17
真的很好,谢谢
支持(0)  反对(0)  回复

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务