<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<base href="<%=basePath%>">
<title>添加用户</title>
<script type="text/javascript">
var xmlhttp;
function test(){
var username = document.getElementById("userName").value;
//创建ajax中的XMLHttpRequest对象,针对于不同浏览器
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}else{
xmlhttp = new ActiveXObject("MSXML2.XMLHTTP.6.0")
}
xmlhttp.onreadystatechange= test1;
xmlhttp.open("GET","checkUserName.action?userName="+username, true);
xmlhttp.send(null);
}
function test1(){
var sp = document.getElementById("msg");
if(xmlhttp.readyState==4){
var flag = xmlhttp.responseText;
if(flag==0)
sp.innerHTML = "<font color='red'>用户名已存在</font>";
else if(flag==1)
sp.innerHTML = "<font color='green'>用户名可以使用</font>";
}
}
</script>
</head>
<body>
<s:form theme="xhtml" action="addUser.action" method="post">
<%
String str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String password = "";
for (int i = 0; i < 6 ; i++) {
int k = (int) (Math.random() * 36);
char c = str.charAt(k);
password += c ;
}
session.setAttribute("password",password);
%>
<s:textfield id="userName" name="userName" label="用户名" οnblur="test()"></s:textfield>
<span id="msg"></span><<br/>
<s:textfield value="%{#session.password}" name="password" label="密码"></s:textfield>
<s:select label="请选择该用户的角色" name="roleName" list="{'teacher','admin','browser'}">
</s:select>
<s:submit value="提交"></s:submit>
</s:form>
</body>
</html>