现在想实现一个注册 页面
我要在数据库里面判定该账户是否存在 (这个可以判定) 关键是我 servlect 里面判断后的 结果我想放在 jsp 里面显示出来
问:怎么让jisp 页面显示出我servlet 里面的值
还有 <input type="file" id="aa"> 谁知道 怎么获取这个控件的 值 value 获取不到谁要是有简单的验证码 代码也发个给我 谢谢
我要在数据库里面判定该账户是否存在 (这个可以判定) 关键是我 servlect 里面判断后的 结果我想放在 jsp 里面显示出来
问:怎么让jisp 页面显示出我servlet 里面的值
还有 <input type="file" id="aa"> 谁知道 怎么获取这个控件的 值 value 获取不到谁要是有简单的验证码 代码也发个给我 谢谢
$.ajax({
type : "POST",
url : "userAction.do?dispatch=isExitCode",
data : "code="+loginName.value,
success : function(msg) {
if(msg=="1"){
$('.remindOfUserName').html('该用户名已经被占用,请选择其他用户名!').css('color','red');
loginName.select();
return false;
}else{
$('.remindOfUserName').html('恭喜,该用户名可用!').css('color','green');
}
}
});
验证码网上有很多的例子,你随便搜个验证码的jsp页面在一调用就行了,很简单的!
onblue 触发事件 ajax请求后台 上面有代码。
if(true){
request.setAttribute("isreg", "可以注册");
}else{
request.setAttribute("isreg", "不可以注册");
}//jsp页面
${isreg}
还是有点不会啊看我代码
String name=request.getParameter("email");
chaXunUser cx=new chaXunUser();
boolean b=cx.selectUser(name);
if(b){
//这里面是注册不成功的内容 }这个是 servlet的 代码 已经可以判定了 怎么返回注册不成功的内容 个jsp页面啊
代码和1楼没有多大区别,你有什么不懂的地方问出来
function likai(){
if(document.getElementById("aa").value!=""){
document.getElementById("aa").value=${isreg};
}
}这样 也不行啊
boolean b=cx.selectUser(name);
if(b){
//这里用什么方法返回 true 或 false
}还有就是 JSP 页面怎么接受啊
if(document.getElementById("aa").value!=""){
document.getElementById("aa").value=${isreg};
}
}
你这个代码是做什么用的?
aa是一个file标签,怎么能这样操作。
${isreg}这个是显示你保存在作用域的值。
function likai 是我一个 鼠标离开触发的函数
这个我知道 aa 是我账户文本域的 id 我要判断 是否输入过 账户 如果有输入就 执行检测 账户是否存在啊
return ture
得了 我给你写一个你看着把//检查用户名是否已经存在
$.ajax({
type : "POST",
url : "userAction.do",
data : "userName="+loginName.value,//这里去后台取userName这个变量
success : function(msg) {
if(msg==true){
alert("用户名重复,请您重现填写");
}else
alert("用户名正确!");
});那里有不懂速度问
哥哥们 我也很纠结啊 我在 servlet 里面会返回 关键是我 在 jsp 页面中就不会接收了 就是这个
boolean bl=false;
String sql="select uname from users where uname=?";
Connection conn=DBUtil.getConnection();
PreparedStatement pst=null;
ResultSet rst=null;
try {
pst=conn.prepareStatement(sql);
pst.setString(1, name);
rst=pst.executeQuery();
if(rst.next()){
bl=true;
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
try {
DBUtil.close(conn, pst, rst);
} catch (SQLException e) {
e.printStackTrace();
}
这个是我 servlet 里面 的代码 String name=request.getParameter("email");
chaXunUser cx=new chaXunUser();
boolean b=cx.selectUser(name);
if(b){
request.setAttribute("isreg", "可以注册");
}else{request.setAttribute("isreg", "不可以注册");}这个是 我JSP 页面里面的代码:
<script type="text/javascript">
function ciclk(){
document.getElementById("aa").value="";
}
function likai(){
if(document.getElementById("aa").value==""){
document.getElementById("aa").value="支持,中,英,数字";
}
if(document.getElementById("aa").value!=""){
//document.getElementById("aa").value=;
}
}
</script>
<td>注册账户:</td>
<td align="left"><input id="aa" type="text" name="email" value="支持,中,英,数字" onclick="ciclk()" onblur="likai()"></td>
借用一下八楼哥们的代码function likai(){
if(document.getElementById("aa").value==""){
document.getElementById("aa").value="支持,中,英,数字";
}
if(document.getElementById("aa").value!=""){
var username = document.getElementById("aa").value;
$.ajax({
type : "POST",
url : "userAction.do", //这个看你web.xml里面怎么配置的
data : "userName="+username,//这里去后台取userName这个变量
success : function(msg) {
if(msg=="success"){
alert("用户名重复,请您重现填写");
}else{
alert("用户名正确!");
}
});
}
}
-------------------华丽的分割线--------------------servlet代码String name = request.getParameter("userName");
chaXunUser cx=new chaXunUser();
boolean b=cx.selectUser(name);
PrintWriter pw = response.getWriter();
if(b){
pw.write("success");
}else{
pw.write("error");
}
pw.close();
return;