JSP中特殊字符处理
2015-09-04 16:34
465 查看
JSP中用form表单(Post请求)可以传送特殊字符到服务器,但当使用get请求或者通过链接地址(也是get请求)时,如遇到+、-等特殊字符就会截断其后的值。本文没有解决get请求中含这些字符的问题,但给出了一种转换方法。
如上所说,post请求可以传送特殊字符。所以,可以将get请求转换成post请求。又js中可以获取form元素并提交请求,所以可以将get请求需要传送的数据放在type类型为hidden的input中,然后通过js代码和form表单实现传送特殊字符。示例代码如下:
one.jsp
two.jsp
如上所说,post请求可以传送特殊字符。所以,可以将get请求转换成post请求。又js中可以获取form元素并提交请求,所以可以将get请求需要传送的数据放在type类型为hidden的input中,然后通过js代码和form表单实现传送特殊字符。示例代码如下:
one.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <% request.setCharacterEncoding("utf-8"); %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>one</title> </head> <body> <form action="two.jsp" method="post" id="1"> <input type="hidden" name="value" value="one+-*/"> </form> <form action="two.jsp" method="post" id="2"> <input type="hidden" name="value" value="two+-*/"> </form> <a href="javascript:send('1')">one</a> <a href="javascript:send('2')">tow</a> </body> <script type="text/javascript"> function send(formId){ document.getElementById(formId).submit(); } </script> </html>
two.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <% request.setCharacterEncoding("utf-8"); String value = request.getParameter("value"); %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>two</title> </head> <body> 传过来的值为<%=value %> </body> </html>
相关文章推荐
- js日期控件
- js实现浮动在网页右侧的简洁QQ在线客服代码
- JavaScript二维数组的使用及删除指定元素
- javascript JSON解析函数
- JS实现先显示大图后自动收起显示小图的广告代码
- JavaScript随笔(一):数据类型
- JavaScript Engines
- JavaScript实现的多个图片广告交替显示效果代码
- Ajax、json
- seajs简记
- js中对style中的多个属性进行设值
- Servlet端 接收不到4096,8192长度的JSON参数
- 【原创】Loadrunner使用json格式请求数据并参数化
- JavaScript 开发者必备的10款 SublimeText 插件
- javascript实现OOP编程
- JavaScript学习笔记6-单元测试框架之Jasmine
- 基于JS实现简单的样式切换效果代码
- 利用AXIS2传递JSON数据
- 利用AXIS2传递JSON数据
- best javascript framework list -- 最好的js框架