2个jsp页面传递参数(多个参数)导致错误。
2个jsp页面分别是a.jsp  b.jspa.jsp的代码如下:
out.println("<td class=text><a href=aa.do?act=1&firstname="+firstname+"&secondname=""+secondname+
...................
>")参数多达7个以上。 后面省略。
现在发现有几个问题
1  firstname或者secondname  有 如下情形的 
firstname= ‘mike aadson‘  or  secondname=‘jruce andson’
传递到b.jsp只会收到firstname= ‘mike‘  or secondname=‘jruce'
这样导致数据错误2 更严重的是 有时候后面的参数数据丢失,后面还有email addresss brithday 等数据
救国到达b.jsp发现secondname后面的数据全部丢失。 什么原因 如何解决??

解决方案 »

  1.   

     jsp传递中文参数、空格以及表单内容换行问题解决小结
       Jsp页面使用URL编码传递中文参数的情况下,在参数的解析过程中会出现乱码。由于java在设计的时候考虑到了国际化的问题,在java源程序编译成字节码的时候默认使用的是UTF-8编码。而在web运用上,由于不同的浏览器向服务器发送的信息采用的编码方式不同,在由像tomcat之类的服务器解码的时候会由于编码方式的不同而产生乱码,这是一个会困扰jsp初学者很久的问题。以前在使用struts的时候不需要处理这些问题,前些天在做一个简单的jsp页面的时候碰到这个问题。经过半天的摸索,基本解决了该问题。   例子中a.jsp页面通过URL编码的方式传递中文参数,在b.jsp中对该参数进行解析。
    a.jsp源代码
    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>天津工业网</title>
    </head>
     
    <body>
    <% 
           String str_test = "工业网";
    %>
    <form method=post action="b.jsp?test=<%=java.net.URLEncoder.encode(str_test) %>"> 
             <input type="submit" value="Submit" name="提交">   
     </form>
     
    </body>
    </html>b.jsp源代码<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head>
     
    <body>
     
    <% 
           String str = new String(request.getParameter("test").getBytes("ISO8859_1"));
    %> 
     <BR>
     <%=str %> 
    </body>
    </html>
       说明:在使用了java.net.URLEncoder.encode 编码后,页面获取参数request.getParameter后需要使用ISO8859_1编码转换。此外,在jsp的字符集声明中把charset=UTF-8也没有问题。jsp传递中文参数乱码问题的解决方法在用中文作为参数传给处理页面进行处理时发现是乱码。以往听说过是由于编码问题造成的,但就是无法解决。今天总算找到相关的解决方法。很简单:在每个 jsp页面加上下面3行 <%@ page pageEncoding="GBK"%> <%@ page contentType="text/html;charset=GBK"%> <%request.setCharacterEncoding("GBK");%> 把GBK改成gb2312也可以,区别就是GBK不仅支持简体中文还支持繁体而gb2312只支持简体中文 
      

  2.   

    there are some errors in my updated java codes.out.println("<td class=text><a href=aa.do?act=1&firstName="<%=java.net.URLEncoder.encode(firstName)%>"&secondName="<%=java.net.URLEncoder.encode(secondName)%>"&birthday="+berrors:An error occurred at line: 1,095 in the generated java file
    Syntax error, insert "}" to complete BlockAn error occurred at line: 1,095 in the generated java file
    Syntax error, insert "else Statement" to complete IfStatementAn error occurred at line: 1,095 in the generated java file
    Syntax error, insert "}" to complete BlockAn error occurred at line: 1,106 in the generated java file
    Syntax error on token "}", delete this tokenStacktrace:
    at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:923)
    at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:462)
    at org.apache.jsp.jsp.oddsmatrix.backoffice.templateContentOnly_jsp._jspx_meth_tiles_005finsert_005f0(templateContentOnly_jsp.java:6437)
    at org.apache.jsp.jsp.oddsmatrix.backoffice.templateContentOnly_jsp._jspService(templateContentOnly_jsp.java:653)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)
    at org.apache.catalina.cor
      

  3.   

    out.println(" <td class=text> <a href=aa.do?act=1&firstName=" <%=java.net.URLEncoder.encode(firstName)%>"&secondName=" <%=java.net.URLEncoder.encode(secondName)%>"&birthday="+b
    改成下面这样试试
    String firstName = java.net.URLEncoder.encode(firstName);
    String secondName= java.net.URLEncoder.encode(secondName);
    out.println(" <td class=text> <a href=aa.do?act=1&firstname="+firstname+"&secondname=""+secondname+
    ...................
    >") 
      

  4.   

    out.println(" <td class=text> <a href=aa.do?act=1&firstName=‘<%=java.net.URLEncoder.encode(firstName)%>’&secondName=‘<%=java.net.URLEncoder.encode(secondName)%>’&birthday=‘+b 参数请用单引号
      

  5.   

    out.println(" <td class=text> <a href=aa.do?act=1&firstName"+java.net.URLEncoder.encode(firstName)+"&secondName="=java.net.URLEncoder.encode(secondName)+"&birthday=‘+b