一、引入js
二、写一个js方法,通过正则表达式获取URL后面的参数
test3.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"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <script type="text/javascript" src="/javaweb1/js/jquery-1.11.0.js"></script> </head> <script type="text/javascript"> $(function(){ var str = getQueryString("name"); alert(str); }) function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return decodeURI(r[2]); return null; } </script> <body> </body> </html>
浏览器输入:http://localhost:1080/javaweb1/test6/test3.jsp?name=测试代码
这种方法也解决了get中文乱码的问题