日期:2014-05-18  浏览次数:20627 次

急!请大家帮下忙!
javascript的程序如下:
function   listInsert()
{
    var   i=window.prompt( '建立数据 ', 'ipsege ');
    if(i.length> 10)   window.alert( "最多输入10个数据 ");  
    else
    {
    if(i!=null)
            {
    if(i== " ")   window.alert( "数据不能为空 ");
    else   var   j=window.prompt( '插入元素 ', 'p ');
            }
            if(j!=null)
            {
            if(j== " ")   window.alert( "数据不能为空 ");
    else   var   k=window.prompt( '插入位置 ', '3 ');
            if(k!=null)
            {
    if(isNaN(k))   window.alert( "请输入数字 ");
    else   if(k== " "||parseInt(k) <=0||parseInt(k)> i.length+1)   window.alert( "输入的位置不合法 ");
    else
    {
    frame=parent.frames[3];
                                    frame.location.href= "listInsert.jsp?k1= "+i+ "&k2= "+j+ "&k3= "+k;
    }
            }
            else
            {
            frame=parent.frames[3];
            frame.location.href= "listInsert.jsp?k= "+k;
            }
            }
    }
}

jsp中的内容如下:
<%
String   k1=request.getParameter( "k1 ");
String   k2=request.getParameter( "k2 ");
String   k3=request.getParameter( "k3 ");
out.println(k1);
out.println( " <br> "+k2);
out.println( " <br> "+k3);
%>

为什么输入一般的字符串在jsp中能够得到它们的值,而当我输入   #     %     &     +   这四个字符的时候就会出问题呢?

------解决方案--------------------
有一点错,看你的程序,你需要分别escape才对
frame.location.href= "listInsert.jsp?k1= "+escape(i)+ "&k2= "+escape(j)+ "&k3= "+escape(k);