首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

稽查用户名是否可用

2011-12-11 
检查用户名是否可用!各位大哥有检查用户名是否可用的代码吗?不想用ajax啊!ajax看不懂![解决办法]不用AJAX

检查用户名是否可用!
各位大哥有检查用户名是否可用的代码吗?不想用ajax啊!ajax看不懂!

[解决办法]
不用AJAX 好像想不出阿訇iyou其他什么比较好的方法
[解决办法]
关注
[解决办法]
肯定有,再找找!不用ajax就用iframe吧,其实都一样!ajax不是流行嘛
[解决办法]
正在学Ajax
[解决办法]
public boolean zhuCu(String username,String password)//�û�注册��
{
jdbcConnection();
try {
String sq= "select username from zhuce where username= ' "+username+ " ' ";
ResultSet rs=st.executeQuery(sq);
if(rs.next()){
System.out.println( "用户名以存在 ");
return false;
}

String sql= "insert into zhuce(username,password) values(?,?) ";
pst=con.prepareStatement(sql);
pst.setString(1,chString(username));
pst.setString(2,chString(password));
pst.executeUpdate();
return true;
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
return false;
}
[解决办法]
ajax
[解决办法]
你不用ajax可以这么做啊,提交数据到后台然后返回一个页面提示用户该用户名是否可用(可弹出一个对话框提示,点击确定按钮后),再返回注册页面,从后台得到刚才提交的数据,然后一一对应填充至用户填写的位置不就行了啊,不过还是推荐使用ajax,这样可以提高用户的体验度,更见人性化。
[解决办法]


var http_request = false;

function send_request(method,url,content,responseType,callback) {//??????????????????
http_request = false;


if(window.XMLHttpRequest) { //Mozilla
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {//MiME
http_request.overrideMimeType( "text/xml ");
}
}
else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject( "Msxml2.XMLHTTP ");
} catch (e) {
try {
http_request = new ActiveXObject( "Microsoft.XMLHTTP ");
} catch (e) {}
}
}
if (!http_request) {
window.alert( "XMLHttpRequest. ");
return false;
}
if(responseType.toLowerCase()== "text ") {

http_request.onreadystatechange = callback;
}
else if(responseType.toLowerCase()== "xml ") {

http_request.onreadystatechange = callback;
}
else {
window.alert( " ");
return false;
}
// URL
if(method.toLowerCase()== "get ") {
http_request.open(method, url, true);
}
else if(method.toLowerCase()== "post ") {
http_request.open(method, url, true);
http_request.setRequestHeader( "Content-Type ", "application/x-www-form-urlencoded ");
}
else {
window.alert( "http ");
return false;
}
http_request.send(content);
}


//验证用户名是否存在
function ValidatorName()
{

var name = document.getElementById( "username ");
if(name.value.length > 0)
send_request( "POST ", "/webapps/registerAction.do?method=checkname&name= "+name.value,null, "TEXT ",respondCheckName);


else
{
//用户名为空..则不提交
return ;
}

}

function respondCheckName()
{
if (http_request.readyState == 4)
{
if (http_request.status == 200)
{
var context = http_request.responseTEXT;
if(context!=null)
{

if(context.indexOf( "true ")==-1)
{//存在}
else
{ //不存在}
}
}
}
}


Action代码:



PrintWriter out = response.getWriter();

String username = request.getParameter( "name ");

if(username==null)
{
out.write( "false ");
return null;
}
else
{
//查询数据库

out.write( "true ");
return null;
}

热点排行
Bad Request.