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

为何JSP页面注册成功仍显示异常提示

2012-01-14 
为何JSP页面注册成功仍显示错误提示注册成功后仍显示:注册时出现错误,请稍后再试 reg.jsp源码如下:%@pa

为何JSP页面注册成功仍显示错误提示
注册成功后仍显示:
"注册时出现错误,请稍后再试 "
reg.jsp源码如下:
<%@   page   language= "java "   contentType= "text/html;   charset=GB2312 "   pageEncoding= "GB2312 "%>
<%@   page   session= "true "   %>
<jsp:useBean   id= "user "   scope= "page "   class= "goodsshop.run.op_user "   />
<%
String   mesg   =   " ";
String   submit   =   request.getParameter( "Submit ");
if   (submit!=null   &&   !submit.equals( " "))   {
if(user.add(request)){
session.setAttribute( "username ",user.getUserName());
session.setAttribute(   "userid ",   Long.toString(   user.getUserid()   )   );
response.sendRedirect( "info.jsp?action=regok ");
}   else   if   (!user.getMessage().equals( " "))   {
mesg   =   user.getMessage();
}   else
mesg   =   "注册时出现错误,请稍后再试 ";
}


%>
<script   language= "javascript ">

function   openScript(url,name,   width,   height){
var   Win   =   window.open(url,name, 'width= '   +   width   +   ',height= '   +   height   +   ',resizable=1,scrollbars=yes,menubar=no,status=yes '   );
}

function   checkform()   {
if   (document.form1.username.value== " "){
alert( "用户名不能为空 ");
document.form1.username.focus();
return   false;
}
if   (document.form1.passwd.value== " "){
alert( "用户密码不能为空 ");
document.form1.passwd.focus();
return   false;
}
if   (document.form1.passwd.value!=document.form1.passconfirm.value){
alert( "确认密码不相符! ");
document.form1.passconfirm.focus();
return   false;
}

return   true;
}

</script>
<%@include   file= "/inc/head.inc "%>
<form   name= "form1 "   method= "post "   action= "reg.jsp ">
    <%if   (!mesg.equals( " "))   out.println( " <p> <font   color=#ff0000> "+   mesg   +   " </font> </p> ");%>
        <table   width= "450 "   border= "0 "   cellspacing= "1 "   cellpadding= "1 "   align=center>
  <tr> </tr>
            <tr>
                <td   colspan= "2 "   align= "center "> <b> <font   color= "#0000FF "> 用户注册 </font> </b> </td>
            </tr>
          <tr> </tr>
            <tr>
                <td   width= "171 "   align= "right "> 用户名: </td>
                <td   width= "272 ">
                    <input   type= "text "   name= "username "   maxlength= "20 "   size= "14 "   >


                </td>
            </tr>
            <tr>
                <td   width= "171 "   align= "right "> 密码: </td>
                <td   width= "272 ">
                    <input   type= "password "   name= "passwd "   maxlength= "20 "   size= "14 ">
                </td>
            </tr>
            <tr>
                <td   width= "171 "   align= "right "> 确认密码: </td>
                <td   width= "272 ">
                    <input   type= "password "   name= "passconfirm "   maxlength= "20 "   size= "14 ">
                </td>
            </tr>
            <tr>
                <td   width= "171 "   align= "right "> 真实姓名: </td>
                <td   width= "272 ">
                    <input   type= "text "   name= "names "   maxlength= "20 "   size= "14 ">
                </td>
            </tr>
            <tr>
                <td   width= "171 "   align= "right "> 性别: </td>
                <td   width= "272 ">
                    <select   name= "sex ">
                        <option> 男 </option>
                        <option> 女 </option>
                    </select>
                </td>
            </tr>
            <tr>
                <td   width= "171 "   align= "right "> 联系地址: </td>
                <td   width= "272 ">
                    <input   type= "text "   name= "address "   maxlength= "150 "   size= "40 ">
                </td>
            </tr>


    <tr>
                <td   width= "171 "   align= "right "> 联系邮编: </td>
                <td   width= "272 ">
                    <input   type= "text "   name= "post "   maxlength= "8 "   size= "8 ">
                </td>
            </tr>
            <tr>
                <td   width= "171 "   align= "right "> 联系电话: </td>
                <td   width= "272 ">
                    <input   type= "text "   name= "phone "   maxlength= "25 "   size= "16 ">
                </td>
            </tr>
            <tr>
                <td   width= "171 "   align= "right "> 电子邮件: </td>
                <td   width= "272 ">
                    <input   type= "text "   name= "email "   maxlength= "50 "   size= "25 ">
                </td>
            </tr>
            <tr>
                <td   width= "171 "   align= "right "> &nbsp;   </td>
                <td   width= "272 ">
                    <input   type= "submit "   name= "Submit "   value= "注册 "   onclick= "javascript:return(checkform()); ">
                    <input   type= "reset "   name= "reset "   value= "取消 ">
                </td>
            </tr>
        </table>
    </form>

<%@include   file= "/inc/tail.inc "%>

[解决办法]
说明lz下面代码的逻辑流程有问题,总是进入最后的else

if(user.add(request)){
session.setAttribute( "username ",user.getUserName());
session.setAttribute( "userid ", Long.toString( user.getUserid() ) );
response.sendRedirect( "info.jsp?action=regok ");
} else if (!user.getMessage().equals( " ")) {
mesg = user.getMessage();
} else
mesg = "注册时出现错误,请稍后再试 ";

[解决办法]
是你的User这个bean里面出错了吧。
user.add(request)会返回什么?
------解决方案--------------------


lz调用user.add(request)方法能够将数据写入数据库吗?有没有报异常?
[解决办法]
能写入数据库,add()方法还是返回false???
lz的qq多少?
[解决办法]
发贴子说的太慢。。。

热点排行