JSP中传输数据的问题?

lsfyfan 2002-04-03 09:40:56
请问各位高手:
我想杂JSP中传输数据:
http://localhost/index.jsp?w=where i=1
问题就是我怎么样才能实现参数的值中带有 "=" 号?
(参数:w 值:where i=1)
...全文
72 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wizardfan 2002-04-11
  • 打赏
  • 举报
回复
或用URLEncoder.Encode()
wizardfan 2002-04-04
  • 打赏
  • 举报
回复
差点忘了

/* BASE64 encoding encodes 3 bytes into 4 characters.
|11111122|22223333|33444444|
Each set of 6 bits is encoded according to the
toBase64 map. If the number of input bytes is not
a multiple of 3, then the last group of 4 characters
is padded with one or two = signs. Each output line
is at most 76 characters.
*/

class Base64OutputStream extends FilterOutputStream
{ public Base64OutputStream(OutputStream out)
{ super(out);
}

public void write(int c) throws IOException
{ inbuf[i] = c;
i++;
if (i == 3)
{ super.write(toBase64[(inbuf[0] & 0xFC) >> 2]);
super.write(toBase64[((inbuf[0] & 0x03) << 4) |
((inbuf[1] & 0xF0) >> 4)]);
super.write(toBase64[((inbuf[1] & 0x0F) << 2) |
((inbuf[2] & 0xC0) >> 6)]);
super.write(toBase64[inbuf[2] & 0x3F]);
col += 4;
i = 0;
if (col >= 76)
{ super.write('\n');
col = 0;
}
}
}

public void flush() throws IOException
{ if (i == 1)
{ super.write(toBase64[(inbuf[0] & 0xFC) >> 2]);
super.write(toBase64[(inbuf[0] & 0x03) << 4]);
super.write('=');
super.write('=');
}
else if (i == 2)
{ super.write(toBase64[(inbuf[0] & 0xFC) >> 2]);
super.write(toBase64[((inbuf[0] & 0x03) << 4) |
((inbuf[1] & 0xF0) >> 4)]);
super.write(toBase64[(inbuf[1] & 0x0F) << 2]);
super.write('=');
}
}

private static char[] toBase64 =
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/'
};

private int col = 0;
private int i = 0;
private int[] inbuf = new int[3];
}
wizardfan 2002-04-04
  • 打赏
  • 举报
回复
是不是要改变一下“ ”等的编码,如space变成‘%20’?试一下下面的方法

public static String base64Encode(String s) {
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
Base64OutputStream out = new Base64OutputStream(bOut);
try{
out.write(s.getBytes());
out.flush();
} catch (IOException exception){
}
return bOut.toString();
}
tagger 2002-04-04
  • 打赏
  • 举报
回复
建议 直接传递i=1
================================================================

CSDN 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!

★ 浏览帖子速度极快![建议系统使用ie5.5以上]。 ★ 多种帖子实现界面。
★ 保存帖子到本地[html格式]★ 监视您关注帖子的回复更新。
★ 可以直接发贴、回复帖子★ 采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录!
★ 支持在线检测程序升级情况,可及时获得程序更新的信息。

★★ 签名 ●
可以在您的每个帖子的后面自动加上一个自己设计的签名哟。

Http://www.ChinaOK.net/csdn/csdn.zip
Http://www.ChinaOK.net/csdn/csdn.rar
Http://www.Chi
shingle 2002-04-04
  • 打赏
  • 举报
回复
其实用 JavaScript 来处理这种问题可能会容易一点,比如:

===================================================================

<script language=javaScript>
function goForward(){
document.testForm.submit() ;
}
</script>

<form name="testForm" action="http://localhost/index.jsp" method=post>
<input type=hidden name="w" value="where i=1">
<a href="javaScript:goForward(); ">TEST</a>
</form>

===================================================================

这样的话 Serlvet 不用再做额外的运算就能得到你的参数,这岂不是更好 ?
swingcoder 2002-04-03
  • 打赏
  • 举报
回复
建议如下:
1.可用变通的方法,如将=改为@等特殏符号,再在服务器端进行分析还原。
2.根本没必要传递where i=1,既然你已经知道i参数作何用,直接传递i=1即可,在jsp中改写为where i=1进行查询!!

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧