后台代码:
@RequestMapping(value="/testText.htm")
public void testText(String text,HttpServletResponse resp){
try {
resp.getWriter().write("200");
resp.getWriter().flush();
} catch (IOException e) {
e.printStackTrace();
}
}
前端:
<%@ page language="java" import="java.util.*" contentType="text/html;charset=utf-8"%>
<!DOCTYPE h1 PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript">
function sub(){
var text = document.getElementById("text").value;
$.ajax( {
type : "POST",
url : "<%=request.getContextPath()%>/index/testText.htm",
data : {
'remark' : text,
},
dataType: "json",
success : function(data) {
alert(data);
},
error :function(){
alert("网络连接出错!");
}
});
}
</script>
</head>
<body>
<h3>请输入需要测试的文本:</h3>
<input type="text" id="text">
<button onclick="sub()">提交</button>
</body>
</html>