错误提示如下,请问如何解决?
description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: An exception occurred processing JSP page /liuyan2.jsp at line 2219:   temp1=request.getParameter("txttit");   
20:   temp2=request.getParameter("txtaut");   
21:   temp3=request.getParameter("txtart");   
22:   n=temp1.length()*temp2.length()*temp3.length();   
23:   if(n!=0){   
24:   temp=(String)application.getAttribute("num");   
25:   n=Integer.parseInt(temp);   
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause java.lang.NullPointerException
org.apache.jsp.liuyan2_jsp._jspService(liuyan2_jsp.java:76)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet

解决方案 »

  1.   

    22: n=temp1.length()*temp2.length()*temp3.length(); 这三个参数可能为空.做个判断再.length
      

  2.   

    接收的三个参数校验一下:
    try{
     temp1=request.getParameter("txttit"); 
     temp2=request.getParameter("txtaut"); 
     temp3=request.getParameter("txtart"); 
    }catch(Exception e){
      //
    }
      

  3.   

    java.lang.NullPointerException
    空指针异常,请检查每个变量是否为null
      

  4.   

    liuyan2.jsp at line 22
    说明你这个jsp的22行中的变量有可能有Null,null.length就会报这个异常
      

  5.   

    那怎么修改呀?麻烦帮忙该下哦,多谢啦!
    <body   bgcolor="#FFFFFF"   text="#000000">   
      <p>&nbsp;</p>   
      <p   align="center"><b><font   size="5"   color="#FF6633">文物论坛留言板</font></b></p>   
      <hr   size="1">   
      <%   
      int   n;   
      String   temp=new   String();   
      String   temp1=new   String();   
      String   temp2=new   String();   
      String   temp3=new   String();   
      try{
      temp1=request.getParameter("txttit"); 
      temp2=request.getParameter("txtaut"); 
      temp3=request.getParameter("txtart"); 
      }catch(Exception e){
      //
      }
       n=temp1.length()*temp2.length()*temp3.length();    
      if(n!=0){   
      temp=(String)application.getAttribute("num");   
      n=Integer.parseInt(temp);   
      n=n+1;   
      temp=temp.valueOf(n);   
      application.setAttribute("num",temp);   
      application.setAttribute("tit"+temp,temp1);   
      application.setAttribute("aut"+temp,temp2);   
      application.setAttribute("art"+temp,temp3);   
      %>   
      <p>&nbsp;</p>   
      <p   align="center">留言成功!</p>   
      <%   
      }   
      else{   
      %>   
      <p   align="center"><font   color="#FF0000">不添加作者、标题和内容,留言失败!
    </font></p>   
      <%   
      }   
      %>   
      <p   align="center"><a   href="liuyan1.jsp">返回首页</a>   </p>   
      </body>  
    </html>
      

  6.   


    n=
    temp1 == null ? 0 : temp1.length() + 
    temp2 == null ? 0 : temp2.length() + 
    temp3 == null ? 0 : temp3.length()
      

  7.   

    String temp1=new String(); 
    String temp2=new String(); 
    String temp3=new String(); 
    temp1=request.getParameter("txttit"); 
    temp2=request.getParameter("txtaut"); 
    temp3=request.getParameter("txtart"); 这种写法。上面的temp1-temp3的new String都被冲掉了
    String temp1=request.getParameter("txttit"); 
    String temp2=request.getParameter("txtaut"); 
    String temp3=request.getParameter("txtart");这里try catch 不要你来的真准,我正准备下线
      

  8.   

    不好意思,我找你教的修改了,但是运行之后错误提示是:
    org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 18 in the jsp file: /liuyan2.jsp
    Syntax error, insert ";" to complete Statement
    15:   String temp1=request.getParameter("txttit"); 
    16:   String temp2=request.getParameter("txtaut"); 
    17:   String temp3=request.getParameter("txtart"); 
    18:   n=temp1 == null ? 0 : temp1.length() + temp2 == null ? 0 : temp2.length() + temp3 == null ? 0 : temp3.length() 
    19:   if(n!=0){   
    20:   temp=(String)application.getAttribute("num");   
    21:   n=Integer.parseInt(temp);   
    An error occurred at line: 20 in the jsp file: /liuyan2.jsp
    temp cannot be resolved
    17:   String temp3=request.getParameter("txtart"); 
    18:   n=temp1 == null ? 0 : temp1.length() + temp2 == null ? 0 : temp2.length() + temp3 == null ? 0 : temp3.length() 
    19:   if(n!=0){   
    20:   temp=(String)application.getAttribute("num");   
    21:   n=Integer.parseInt(temp);   
    22:   n=n+1;   
    23:   temp=temp.valueOf(n);   
    An error occurred at line: 21 in the jsp file: /liuyan2.jsp
    temp cannot be resolved
    18:   n=temp1 == null ? 0 : temp1.length() + temp2 == null ? 0 : temp2.length() + temp3 == null ? 0 : temp3.length() 
    19:   if(n!=0){   
    20:   temp=(String)application.getAttribute("num");   
    21:   n=Integer.parseInt(temp);   
    22:   n=n+1;   
    23:   temp=temp.valueOf(n);   
    24:     
    An error occurred at line: 23 in the jsp file: /liuyan2.jsp
    temp cannot be resolved
    20:   temp=(String)application.getAttribute("num");   
    21:   n=Integer.parseInt(temp);   
    22:   n=n+1;   
    23:   temp=temp.valueOf(n);   
    24:     
    25:   application.setAttribute("tit"+temp,temp1);   
    26:   application.setAttribute("aut"+temp,temp2);   
    An error occurred at line: 23 in the jsp file: /liuyan2.jsp
    temp cannot be resolved
    20:   temp=(String)application.getAttribute("num");   
    21:   n=Integer.parseInt(temp);   
    22:   n=n+1;   
    23:   temp=temp.valueOf(n);   
    24:     
    25:   application.setAttribute("tit"+temp,temp1);   
    26:   application.setAttribute("aut"+temp,temp2);   
    An error occurred at line: 25 in the jsp file: /liuyan2.jsp
    temp cannot be resolved
    22:   n=n+1;   
    23:   temp=temp.valueOf(n);   
    24:     
    25:   application.setAttribute("tit"+temp,temp1);   
    26:   application.setAttribute("aut"+temp,temp2);   
    27:   application.setAttribute("art"+temp,temp3);   
    28:   %>   
    An error occurred at line: 26 in the jsp file: /liuyan2.jsp
    temp cannot be resolved
    23:   temp=temp.valueOf(n);   
    24:     
    25:   application.setAttribute("tit"+temp,temp1);   
    26:   application.setAttribute("aut"+temp,temp2);   
    27:   application.setAttribute("art"+temp,temp3);   
    28:   %>   
    29:   <p>&nbsp;</p>   
      

  9.   

    麻烦高手帮我再修改下
    代码:
    <body   bgcolor="#FFFFFF"   text="#000000">   
      <p>&nbsp;</p>   
      <p   align="center"><b><font   size="5"   color="#FF6633">文物论坛留言板</font></b></p>   
      <hr   size="1">   
      <%   
      int   n ;    
      String temp1=request.getParameter("txttit"); 
      String temp2=request.getParameter("txtaut"); 
      String temp3=request.getParameter("txtart"); 
      n=temp1 == null ? 0 : temp1.length() + temp2 == null ? 0 : temp2.length() + temp3 == null ? 0 : temp3.length() 
      if(n!=0){   
      temp=(String)application.getAttribute("num");   
      n=Integer.parseInt(temp);   
      n=n+1;   
      temp=temp.valueOf(n);   
      application.setAttribute("num",temp);  
      application.setAttribute("tit"+temp,temp1);   
      application.setAttribute("aut"+temp,temp2);   
      application.setAttribute("art"+temp,temp3);   
      %>   
      <p>&nbsp;</p>   
      <p   align="center">留言成功!</p>   
      <%   
      }   
      else{   
      %>   
      <p   align="center"><font   color="#FF0000">不添加作者、标题和内容,留言失败!
    </font></p>   
      <%   
      }   
      %>   
      <p   align="center"><a   href="liuyan1.jsp">返回首页</a>   </p>   
    </body>  
    </html>
      

  10.   

    n=temp1 == null ? 0 : temp1.length() + temp2 == null ? 0 : temp2.length() + temp3 == null ? 0 : temp3.length() 改成n=temp1 == null ? 0 : temp1.length() + temp2 == null ? 0 : temp2.length() + temp3 == null ? 0 : temp3.length();
    分号。
      

  11.   

     temp1=request.getParameter("txttit");
     temp2=request.getParameter("txtaut");
     temp3=request.getParameter("txtart");  temp1==null?"":temp1;
     temp2==null?"":temp2;
     temp3==null?"":temp3; n=temp1.length()*temp2.length()*temp3.length(); 
     这样就可以了,至少不会报错。