我的项目概念取决于下拉值,控件将转移到相关的 jsp 页面。
我创建了 4 个下拉值
1.安卓
2.struts
3.弹簧
4.休眠
和4个jsp页面
1.andriod.jsp
2.struts.jsp
3.spring.jsp
4.hibernate.jsp
如果我选择了 andriod 并单击提交按钮意味着控件将被转移到 andriod.jsp 页面,类似地其他值也被转移,
我的问题是
如果我选择 andriod 并单击提交按钮,它总是显示空指针异常...
请任何人解决我的问题。
我建立
1.jsp页面(文件名.jsp)
2.Servlet页面(CatServ.java)
新文件.jsp
<body>
<form action="test" method="post">
<table>
<tr>
<td>
Select the category</td>
<td>
<select>
<option name="andriod" value="lang">Andriod</option>
<option name="java" value="lang">Java</option>
<option name="struts" value="lang">Struts</option>
<option name="spring" value="lang">Spring</option>
<option name="hybernate" value="lang">Hybernate</option>
</select>
</td>
</tr>
<tr>
<td><center>
<input type="submit" value="Submit"></center>
</td>
</tr>
</table>
</form>
</body>
CatServ.java
package container;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class CatServ
*/
@WebServlet("/CatServ")
public class CatServ extends HttpServlet
{
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// TODO Auto-generated method stub
String s=request.getParameter("lang");
System.out.println(s);
if(s.equals("andriod"))
{
RequestDispatcher rd=request.getRequestDispatcher("AndriodServ.jsp");
rd.forward(request, response);
}
else if(s.equals("java"))
{
RequestDispatcher rd=request.getRequestDispatcher("JavaServ.jsp");
rd.forward(request, response);
}
else if(s.equals("struts"))
{
RequestDispatcher rd=request.getRequestDispatcher("StrutsServ.jsp");
rd.forward(request, response);
}
else if(s.equals("spring"))
{
RequestDispatcher rd=request.getRequestDispatcher("SpringServ.jsp");
rd.forward(request, response);
}
else if(s.equals("hibernate"))
{
RequestDispatcher rd=request.getRequestDispatcher("Hybernate.jsp");
rd.forward(request, response);
}
}
}