帮忙看看为什么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.麻烦帮我看下呀~谢谢~
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.麻烦帮我看下呀~谢谢~
这句没有值
String s=null;
if(s.equals("a"))
System.out.println("a");
else
System.out.println("not a");
会报错的~~~~