帮忙看看为什么localhost:8080/bak/index.jsp的时候会有这样的问题:
java.lang.NullPointerException
indextest.service(indextest.java:21)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
<%--
File Name:index.jsp
Author:lxs
Date:2005.10.5
Note:add a attribute to the current session
--%><%response.sendRedirect("servlet/indextest");%>
<%--
File Name:login.jsp
Author:lxs
Date:2005.10.5
Note:provide a interface for the user to login
--%><style type="text/css">
<!--
.input{ backgroud-color:#CCCCFF;border-style:none;
border-top-width:thin;border-right-width:thin;
border-bottom-width:thin;border-left-width:thin}
-->
</style>
<form name="form" method="post" action="dologin.jsp" target="_top">
<center>
<table width="32%" border="0">
<tr>
<td align="right" width="21%">usename:</td>
<td>
<input type="text" name="usename" size="20" class="input">
</td>
<tr>
<td align="right" width="21%">password:</td>
<td>
<input type="password" name="password" size="20" class="input">
</td>
</tr>
<tr>
<td width="21%">
<input type="submit" name="Submit" value="Submit">
</td>
<td>
<input type="reset" name="Submit2" value="Reset">
</td>
</tr>
</table>
</center>
<form>
<%--
File Name:indextest.java
Author:lxs
Date:2005.10.5
Note:add a attribute to the current session
--%>
import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;public class indextest extends HttpServlet
{
public void service(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException
      {
      String cmd=req.getParameter("cmd");
        if(cmd==null)
          {
          resp.sendRedirect("../login.jsp");
          }
          
        /*if(cmd.equals(""))
          {
          resp.sendRedirect("../login.jsp");
          }*/
          
        if(cmd.equals("login"))
          {
          resp.sendRedirect("../login.jsp");
          }
        
        if(cmd.equals("logout"))
          {
          resp.sendRedirect("../logout.jsp");
          }
          
        if(cmd.equals("cart"))
          {
          resp.sendRedirect("../cart.jsp");
          }    
          
        if(cmd.equals("clear"))
          {
          resp.sendRedirect("../clear.jsp");
          }
          
        if(cmd.equals("order"))
          {
          resp.sendRedirect("../order.jsp");
          }
          
        if(cmd.equals("main"))
          {
          resp.sendRedirect("../main.jsp");
          }
          
        if(cmd.equals("list"))
          {
          resp.sendRedirect("../list.jsp");
          }
          
        if(cmd.equals("remove"))
          {
          String id=req.getParameter("id");
          resp.sendRedirect("../remove.jsp?id="+id);
          }
        
        if(cmd.equals("init"))
          {
          resp.sendRedirect("../init.jsp");
          }
          
          //resp.sendRedirect("../login.jsp");
      }
}
但是把indextest第一个if语句以后的if都注释点就可以从index.jsp跳转到login.jsp.麻烦帮我看下呀~谢谢~

解决方案 »

  1.   

    空指针异常,没取到值,sql有错
      

  2.   

    String cmd=req.getParameter("cmd");
    这句没有值
      

  3.   

    从你给出的代码看,CMD的值为NULL。你这样写,执行了第一个if后,页面跳转了,但是servlet运行第二个if会发现CMD为NULL,所以出错。应该从第二个if开始if改成else if
      

  4.   

    if后面等于非TURE~不执行就可以了嘛~~为什么会有错误?
      

  5.   

    if后面的CMD为NULL啊,你试一下下面的代码:
    String s=null;
    if(s.equals("a"))
        System.out.println("a");
    else
        System.out.println("not a");
    会报错的~~~~