当前位置: 代码迷 >> Java Web开发 >> jsp关于空指针的错误问题
  详细解决方案

jsp关于空指针的错误问题

热度:752   发布时间:2009-10-02 18:02:43.0
jsp关于空指针的错误问题
程序代码:
<!--member.jsp实现了新会员注册和会员信息修改-->
<%@page contentType="text/html;charset=gbk"%>
<%@page import ="member.member.biz.*" %>
<%@page import="member.member.model.*" %>
<%
    response.setContentType("text/htm;charset=gbk");
    request.setCharacterEncoding("gbk");
     %>
     <%!
     //该函数用于从当前表单中获取各项数据,并将其封装成ProductEntity对象
     public MemberEntity getMember(HttpServletRequest request)
     {
         MemberEntity member=new MemberEntity();
         member.setID((new Integer(request.getParameter("ID"))).intValue());
         member.setMember_Name(request.getParameter("Member_Name"));
         member.setMember_Sex(request.getParameter("Member_Name"));
         member.setMember_City(request.getParameter("Member_City"));
         member.setMember_Address(request.getParameter("Member_Address"));
         member.setMember_ZipCode(request.getParameter("Member_ZipCode"));
         member.setMember_Tel(request.getParameter("Member_Tel"));
         member.setMember_Email(request.getParameter("Member_Email"));
         member.setMember_Credit(request.getParameter("Member_Credit"));
         member.setMember_Account(request.getParameter("Member_Account"));
         member.setMember_Password(request.getParameter("Member_Password"));
         member.setComment(request.getParameter("Comment"));
        return member;
     }
      %>
      <%
      //type参数用以标识操作类型,register表示注册新会员,edit表示显示会员详细信息
      String type=request.getParameter("type");
      //action参数用以判断表单是否提交
      String action=request.getParameter("action");
      //id参数用以标识会员ID
     
      System.out.println("-------------"+request.getParameter("ID")+"=========");
      
      int id=0;
      //if(request.getParameter("ID")!=null&&request.getParameter("ID")!="")
       id=(new Integer(request.getParameter("ID"))).intValue();
      
      //errMessage表示错误提示信息
      String errMessage="";
      //创建会员对象
      MemberEntity member=new MemberEntity();
      //如果表单被提交,则保存当前会员信息
      if(action!=null)
      {
          MemberBiz memberBiz=new MemberBiz();
          member=getMember(request);
          try
          {
              //如果id为0,表示新会员注册
              if(id==0)
                  memberBiz.registerMember(member);
                  //如果是修改会员信息
                  else
                  memberBiz.updateMember(member);
                  //执行重定位
                  //有错
                  response.sendRedirect("login.jsp");
                  
          }
          catch (Exception e)
          {errMessage=e.getMessage();}
         
      }
      //如果是现实会员详细信息
      else
      {
          if("edit".equals(type))
          {
              MemberBiz memberBiz=new MemberBiz();
              try
              {
                  //调用业务类的findById方法,根据id和表名查找会员
                  member=(MemberEntity)memberBiz.findById("Member",id);
                  
              }
              catch (Exception e)
              { errMessage=e.getMessage();}   
          }
      }
      
       %>
       <html>
               <head>
                   <title>
                       会员详细信息
                   </title>
                       
               </head>
               <body>
                   <%@ include file="../Top.jsp" %>
                       <form name="register" method=post action="member.jsp?action=submit&type=<%=type%>">
                       <table align=center valign=middle cellpadding=1 cellspacing=1 class=table>
                           <tr>
                               <td colspan="2" align="center" class="tr">会员详细信息</td>        
                           </tr>
                           <tr>
                               <td class="td">会员姓名:</td>
                               <td class="td"><input type="radio" name="Member_Sex" value="男"<% if(("男").equals(member.getMember_Sex())) out.print("checked");%>>男
                                               <input type="radio" name="Member_Sex" value="女"<% if(("女").equals(member.getMember_Sex())) out.print("checked");%>>女</td>   
                           </tr>
                       <TR>
                        <td class=td>所在城市:</TD>
                        <TD class=td> <input type="text" name="Member_City" value=<%=member.getMember_City()%>></TD>
                    </TR>
                    <TR>
                        <TD class=td>家庭住址:</TD>
                        <TD class=td><input type="text" name="Member_Address" size=30 value=<%=member.getMember_Address() %>><font color=red>*</font></TD>
   
                    </TR>
                    <TR>
                        <TD class=td>邮政编码:</TD>
                        <TD class=td><input type="text" name="Member_ZipCode" value=<%=member.getMember_ZipCode()%>></TD>
                    </TR>
                    <TR>
                        <TD class=td>联系电话:</TD>
                        <TD class=td><input type="text" name="Member_Tel" value=<%=member.getMember_Tel()%>></TD>
   
                    </TR>
                    <TR>
                        <TD class=td>E-mail:</TD>
                        <TD class=td><input type="text" name="Member_Email" value=<%=member.getMember_Email()%>></TD>
                    </TR>
                    <TR>
                        <TD class=td>会员信誉:</TD>
                        <TD class=td> <select name="Member_Credit">
                        <option value="优秀"<% if(("").equals(member.getMember_Credit())||("优秀").equals(member.getMember_Credit()))
                                                    out.print("selected");%>>优秀</option>
                        <option value="合格"<% if(("合格").equals(member.getMember_Credit()))
                                                    out.print("selected");%>>合格</option>
                        <option value="不合格"<% if(("不合格").equals(member.getMember_Credit()))
                                                    out.print("selected");%>>不合格</option>
                    </select>   
                        </TD>
                    </TR>
                    <TR>
                        <TD class=td>登录账号:</TD>
                        <TD class=td><input type="text" name="Member_Account" value=<%=member.getMember_Account()%>><font color=red>*</font></TD>
                    </TR>
                    <TR>
                        <TD class=td>登录密码:</TD>
                        <TD class=td><input type="text" name="Member_Password" value=<%=member.getMember_Password()%>><font color=red>*</font></TD>
   
                    </TR>
                    <TR>
                        <TD class=td>备注:</TD>
                        <TD class=td><textarea name="Comment" cols=40 rows=4><%=member.getComment()%></textarea></TD>
                    </TR>
                    <TR>
                        <TD colspan=2 align=center class=tr><input class =bt type="button" value="注册" onclick="savaMember();"></TD>
                    </TR>
                    </table>
                        <input type =hidden name=ID value=<%=member.getID()%>>
                       </form>
                       <hr><div align=center ><font color="red" ><%=errMessage%></font></div>
               </body>
               <script language="javascript">
                function saveMember()
                 {
                     if(validate())
                         document.forms[0].submit();
                        
                 }
                 //
                 function validate()
                 {
                     var doc=document.forms[0];
                     if(doc.Member_Name.value=="")
                     {alert("会员姓名不能为空!");
                      return false;}
                     if(doc.Member_Address.value=="")
                     {alert("会员住址不能为空!!");
                      return false;}
                if(doc.Member_Account.value=="")
                     {alert("会员账号不能为空!!");
                       return false;}            
                if(doc.Member_Password.value=="")
                     {alert("会员   密码不能为空!!");
                       return false;}                     
                 return true;
                 }
               </script>        
      
       </html>

运行后错误提示如下:
java.lang.NumberFormatException: null
    java.lang.Integer.parseInt(Integer.java:415)
    java.lang.Integer.<init>(Integer.java:620)
    org.apache.jsp.member.member_jsp._jspService(member_jsp.java:94)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

帮忙给解决一下:在线等待中。
搜索更多相关主题的帖子: 指针  jsp  

----------------解决方案--------------------------------------------------------
程序代码:
<!--member.jsp实现了新会员注册和会员信息修改-->
<%@page contentType="text/html;charset=gbk"%>
<%@page import ="member.member.biz.*" %>
<%@page import="member.member.model.*" %>
<%  
    response.setContentType("text/htm;charset=gbk");
    request.setCharacterEncoding("gbk");
     %>
     <%!  
     //该函数用于从当前表单中获取各项数据,并将其封装成ProductEntity对象
     public MemberEntity getMember(HttpServletRequest request)
     {
         MemberEntity member=new MemberEntity();
         member.setID((new Integer(request.getParameter("ID"))).intValue());
         member.setMember_Name(request.getParameter("Member_Name"));
         member.setMember_Sex(request.getParameter("Member_Name"));
         member.setMember_City(request.getParameter("Member_City"));
         member.setMember_Address(request.getParameter("Member_Address"));
         member.setMember_ZipCode(request.getParameter("Member_ZipCode"));
         member.setMember_Tel(request.getParameter("Member_Tel"));
         member.setMember_Email(request.getParameter("Member_Email"));
         member.setMember_Credit(request.getParameter("Member_Credit"));
         member.setMember_Account(request.getParameter("Member_Account"));
         member.setMember_Password(request.getParameter("Member_Password"));
         member.setComment(request.getParameter("Comment"));
        return member;
     }
      %>
      <%  
      //type参数用以标识操作类型,register表示注册新会员,edit表示显示会员详细信息
      String type=request.getParameter("type");
      //action参数用以判断表单是否提交
      String action=request.getParameter("action");
      //id参数用以标识会员ID
      
      System.out.println("-------------"+request.getParameter("ID")+"=========");
        
      int id=0;
      
      if(request.getParameter("ID")!=null&&request.getParameter("ID")!="")
      {  //不知道与{
匹配的这个}这个放在下面哪个地方?????
       id=(new Integer(request.getParameter("ID"))).intValue();
      
      //errMessage表示错误提示信息
      String errMessage="";
      //创建会员对象
      MemberEntity member=new MemberEntity();
      //如果表单被提交,则保存当前会员信息
      if(action!=null)
      {
          MemberBiz memberBiz=new MemberBiz();
          member=getMember(request);
          try
          {
              //如果id为0,表示新会员注册
              if(id==0)
                  memberBiz.registerMember(member);
                  //如果是修改会员信息
                  else
                  memberBiz.updateMember(member);
                  //执行重定位
                  //有错
                  response.sendRedirect("login.jsp");
                  
          }
          catch (Exception e)
          {errMessage=e.getMessage();}
           
      }
      //如果是现实会员详细信息
      else
      {
          if("edit".equals(type))
          {
              MemberBiz memberBiz=new MemberBiz();
              try
              {
                  //调用业务类的findById方法,根据id和表名查找会员
                  member=(MemberEntity)memberBiz.findById("Member",id);
                  
              }
              catch (Exception e)
              { errMessage=e.getMessage();}     
          }
      }
      
       %>
       <html>
               <head>
                   <title>
                       会员详细信息
                   </title>
                        
               </head>
               <body>
                   <%@ include file="../Top.jsp" %>
                       <form name="register" method=post action="member.jsp?action=submit&type=<%=type%>">
                       <table align=center valign=middle cellpadding=1 cellspacing=1 class=table>
                           <tr>
                               <td colspan="2" align="center" class="tr">会员详细信息</td>         
                           </tr>
                           <tr>
                               <td class="td">会员姓名:</td>
                               <td class="td"><input type="radio" name="Member_Sex" value="男"<% if(("男").equals(member.getMember_Sex())) out.print("checked");%>>男
                                               <input type="radio" name="Member_Sex" value="女"<% if(("女").equals(member.getMember_Sex())) out.print("checked");%>>女</td>     
                           </tr>
                       <TR>
                        <td class=td>所在城市:</TD>
                        <TD class=td> <input type="text" name="Member_City" value=<%=member.getMember_City()%>></TD>
                    </TR>
                    <TR>
                        <TD class=td>家庭住址:</TD>
                        <TD class=td><input type="text" name="Member_Address" size=30 value=<%=member.getMember_Address() %>><font color=red>*</font></TD>
     
                    </TR>
                    <TR>
                        <TD class=td>邮政编码:</TD>
                        <TD class=td><input type="text" name="Member_ZipCode" value=<%=member.getMember_ZipCode()%>></TD>
                    </TR>
                    <TR>
                        <TD class=td>联系电话:</TD>
                        <TD class=td><input type="text" name="Member_Tel" value=<%=member.getMember_Tel()%>></TD>
     
                    </TR>
                    <TR>
                        <TD class=td>E-mail:</TD>
                        <TD class=td><input type="text" name="Member_Email" value=<%=member.getMember_Email()%>></TD>
                    </TR>
                    <TR>
                        <TD class=td>会员信誉:</TD>
                        <TD class=td> <select name="Member_Credit">
                        <option value="优秀"<% if(("").equals(member.getMember_Credit())||("优秀").equals(member.getMember_Credit()))  
                                                    out.print("selected");%>>优秀</option>
                        <option value="合格"<% if(("合格").equals(member.getMember_Credit()))  
                                                    out.print("selected");%>>合格</option>
                        <option value="不合格"<% if(("不合格").equals(member.getMember_Credit()))  
                                                    out.print("selected");%>>不合格</option>
                    </select>     
                        </TD>
                    </TR>
                    <TR>
                        <TD class=td>登录账号:</TD>
                        <TD class=td><input type="text" name="Member_Account" value=<%=member.getMember_Account()%>><font color=red>*</font></TD>
                    </TR>
                    <TR>
                        <TD class=td>登录密码:</TD>
                        <TD class=td><input type="text" name="Member_Password" value=<%=member.getMember_Password()%>><font color=red>*</font></TD>
     
                    </TR>
                    <TR>
                        <TD class=td>备注:</TD>
                        <TD class=td><textarea name="Comment" cols=40 rows=4><%=member.getComment()%></textarea></TD>
                    </TR>
                    <TR>
                        <TD colspan=2 align=center class=tr><input class =bt type="button" value="注册" onclick="savaMember();"></TD>
                    </TR>
                    </table>
                        <input type =hidden name=ID value=<%=member.getID()%>>
                       </form>
                       <hr><div align=center ><font color="red" ><%=errMessage%></font></div>
               </body>
               <script language="javascript">
                function saveMember()
                 {
                     if(validate())
                         document.forms[0].submit();
                          
                 }
                 //
                 function validate()
                 {
                     var doc=document.forms[0];
                     if(doc.Member_Name.value=="")
                     {alert("会员姓名不能为空!");
                      return false;}
                     if(doc.Member_Address.value=="")
                     {alert("会员住址不能为空!!");
                      return false;}
                if(doc.Member_Account.value=="")
                     {alert("会员账号不能为空!!");
                       return false;}              
                if(doc.Member_Password.value=="")
                     {alert("会员   密码不能为空!!");
                       return false;}                     
                 return true;
                 }
               </script>         
        
       </html>

帮忙给指导一下?

----------------解决方案--------------------------------------------------------
  相关解决方案