前台页面:
<html>
<head><link rel="stylesheet" type="text/css" href="${ctx}/themes/b2b2cv2/css/base.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/themes/b2b2cv2/css/default.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/themes/b2b2cv2/css/store.css" />
<script src="${ctx}/themes/b2b2cv2/js/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>URL转换</title>
</head>
<body>
<form id="spurlId" action="" method="post">
<div style="text-align: center;" >
<span>请输入你的URL地址:</span>
<textarea rows="5" cols="80" name="spurl" id="spurl" value=""></textarea>
<input type="button" id="queryurlId" value="查询"/>
</div>
<div style="text-align: center;">
<span>转化后的URL地址:</span>
<textarea rows="5" cols="80" name="spurlzh" id="spurlzh" value=""></textarea>
</div>
</form>
</body>
<script>
$("#queryurlId").click(function(){
var urlold=$("#spurl").val();
$.ajax({
url :"${ctx}/api/shop/goodsLucene!urlgoods.do",
data: {"spurl":urlold},
type : "POST",
dataType : 'json',
success : function(result) {
if(result.result==1){
$('#spurlzh').val(result.message);
}else{
alert(result.message);
}
},
error : function(e) {
alert("出现错误 ,请重试");
}
})
})
</script>
</html>
后台代码:
public String urlgoods(){
HttpServletRequest request = ThreadContextHolder.getHttpRequest();
String url = request.getParameter("spurl");
String urlnew = "";
if(url!=null && !StringUtil.isEmpty(url)){
url=url.replaceAll("&","&");
try {
urlnew = URLDecoder.decode(url, "UTF-8");
this.showSuccessJson(urlnew);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
this.showErrorJson("URL转化失败!");
}
}
return this.JSON_MESSAGE;
}
页面中点击按钮:浏览器地址url动态改变:
var stateObject = {};
var title = "TradeEase";
var newUrl=window.location.href;
if(urlnum ==i){
newUrl = "?"+urlpar;
}
history.pushState(stateObject,title,newUrl);