當我得到以下輸出:JSP腳本無法顯示阿拉伯字符正確
System.out.print(name);
我看不到正確的字符。
我該如何解決?
這裏是我的代碼:
insert.jsp
<%@page import="dao.DaoAdmin"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.sql.PreparedStatement;"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<% request.setCharacterEncoding("UTF8"); %>
<%
String name = request.getParameter("name");
String city = request.getParameter("city");
String phone = request.getParameter("phone");
System.out.print(name);
%>
<!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>
</head>
<body>
<script type="text/javascript">
alert("dsfg");
</script>
</body>
</html>
的index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Sita Ajax test</title>
<script type="text/javascript" charset="UTF-8">
function ajaxRequest() {
var activexmodes = [ "Msxml2.XMLHTTP", "Microsoft.XMLHTTP" ]; //activeX versions to check for in IE
if (window.ActiveXObject) { //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
for (var i = 0; i < activexmodes.length; i++) {
try {
return new ActiveXObject(activexmodes[i]);
} catch (e) {
//suppress error
}
}
} else if (window.XMLHttpRequest) // if Mozilla, Safari etc
return new XMLHttpRequest();
else
return false;
}
// JavaScript Document
function ajaxget() {
var mygetrequest = new ajaxRequest();
mygetrequest.onreadystatechange = function() {
if (mygetrequest.readyState == 4) {
document.getElementById("insert_response").innerHTML = mygetrequest.responseText;
}
};
var name = document.getElementById("name").value;
var city = document.getElementById("city").value;
var phone = document.getElementById("phone").value;
mygetrequest.open("GET", "insert.jsp?name=" + name + "&city=" + city
+ "&phone=" + phone + "", true);
mygetrequest.send(null);
}
</script>
</head>
<body>
<h1>Welcome!</h1>
<form action="javascript:ajaxget()" ; method="post"
accept-charset="UTF-8">
<table style="background-color: #ECE5B6;" width="30%">
<tr>
<th width="50%">Name</th>
<td width="50%"><input type="text" name="name" id="name">
</td>
</tr>
<tr>
<th width="50%">City</th>
<td width="50%"><input type="text" name="city" id="city">
</td>
</tr>
<tr>
<th width="50%">Phone</th>
<td width="50%"><input type="text" name="phone" id="phone">
</td>
</tr>
<tr>
<th></th>
<td width="50%"><input type="submit" value="submit"></td>
</tr>
</table>
</form>
<br />
<br />
<br />
<br />
<!-- Show Message for AJAX response -->
<div id="insert_response"></div>
</body>
</html>