日期:2014-05-17  浏览次数:20759 次

jsp中对表单用javascript初步校验出现的乱码问题

jsp中对表单进行初步校验出现的乱码问题,是span区域中出的比如
<span id="usernamespan"></span>
这上面的用javascript校验会回显消息,中文字符出现了乱码;
下面是jsp源码和javascript代码;
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page contentType="text/html;charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>注册页面</title>
</head>
<script type="text/javascript"
src="${pageContext.request.contextPath }/js/register.js">

</script>
<body style="text-align: center; margin: 0px; padding: 0px">
<c:if test="${message==null }">
<div>
<form
action="${pageContext.request.contextPath }/servlet/RegisterServlet"
method="post">
<div>
用户名:
<input type="text" name="username" onblur="checkUsername(this)"
value="${form.username }" />
<span class="message">${form.errors.username }</span>
<span id="usernamespan"></span>
</div>
<br />
<div>
密 码:
<input type="password" name="password" onblur="checkPassword(this)"
value="${form.password }" />
<span class="message">${form.errors.password }</span>
<span id="passwordspan"></span>
</div>
<br />
<div>
确认密码:
<input type="password" name="repassword"
onblur="checkRepassword(this)" value="${form.repassword }" />
<span class="message">${form.errors.repassword }</span>
<span id="repasswordspan"></span>
</div>
<br />
<div>
邮箱:
<input type="text" name="email" onblur="checkEmail(this)" value="${form.email }" />
<span class="message">${form.errors.email }</span>
<span id="emailspan"></span>
</div>
<br />
<div>
生日:
<input type="text" name="birthday" value="${form.birthday }" />
<span class="message">${form.errors.birthday }</span>
</div>
<br />
<div>
昵称:
<input type="text" name="nickname" onblur="checkNickname(this)" value="${form.nickname}" />
<span class="message">${form.errors.nickname }</span>
<span id="nicknamespan"></span>
</div>
<br />
<div>
验证码:
<input type="text" name="checkcode" onblur="checkCheckcode(this)"/>
<img alt="换一张"
src="${pageContext.request.contextPath }/servlet/GenerateImage"
onclick="changeImage(this)" style="cursor: hand" />
<br />
<span class="message">${form.errors.checkcode }</span>
<span id="checkcodespan"></span>
</div>
<br />
<div>
<input type="hidden"&