0
我有一个登录页面,当我运行它时,它必须检查哪个单选按钮被检查并检查该单选按钮的数据库。 当我运行代码我得到这个错误:在java语言中有2个单选按钮的登录页面
HTTP Status 500 - Request processing failed;
nested exception is java.lang.NullPointerException
和 这是我的网页:
<form action="/HelloWorldInWeb/login" method="post">
<div class="col-lg-12" id="div3">
<div class="form-group input-group" id="div4">
<div class="input-group-addon "><span class="glyphicon glyphicon-eye-open "></span></div>
<input type="text" class="form-control" name="username" id="textbox1" placeholder="Enter your username">
</div>
<div class="form-group input-group" id="div5">
<div class="input-group-addon "><span class="glyphicon glyphicon-eye-close "></span></div>
<input type="text" class="form-control" name="password" id="textbox2" placeholder="Enter your Password">
</div>
<div class="form-group" id="div6">
<label><input type="radio" name="sign" name="checkbox" value="adminstrator" id="adminstrator" checked>Adminstrator</label>
<label><input type="radio" name="sign" name="checkbox" value="admin" id="admin">Admin</label>
</div>
<div class="align">
<button type="submit" class="btn btn-danger">Ok</button>
</div>
</div>
</form>
这是我CONTROLER的servelt:
@SuppressWarnings({ "null", "static-access"})
@RequestMapping(value="/login" , method = RequestMethod.POST)
protected void doPost(HttpServletRequest reque, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String username=reque.getParameter("username");
String password=reque.getParameter("password");
String radio=reque.getParameter("checkbox");
if(radio.equals("admin")){
Boolean t = stdDAO.validate(username, password);
if(t){
out.print(username);
out.print(password);
out.print(" username or password succes");
response.sendRedirect("/HelloWorldInWeb/addozvv");
}
else{
out.print(username);
out.print(password);
out.print("Sorry username or password error");
response.sendRedirect("/HelloWorldInWeb/login");
}
out.close();
}else
if(radio.equals("adminstrator")){
Boolean s = stdDAO.validateadm(username, password);
if(s){
out.print(username);
out.print(password);
out.print(" username or password succes");
response.sendRedirect("/HelloWorldInWeb/addozvv");
}
else{
out.print(username);
out.print(password);
out.print("Sorry username or password error");
response.sendRedirect("/HelloWorldInWeb/login");
}
}
}
这是我的验证:
public Boolean validate(String username, String password) {
boolean t =false;
try{
Connection con = dataSource.getConnection();
PreparedStatement ps =con.prepareStatement
("select * from admins where username=? and password=?");
ps.setString(1, username);
ps.setString(2, password);
ResultSet rs =ps.executeQuery();
t = rs.next();
}catch(Exception e)
{
e.printStackTrace();
}
return t;
}
@Override
public java.lang.Boolean validateadm(String username, String password) {
boolean s =false;
try{
Connection con = dataSource.getConnection();
PreparedStatement ps =con.prepareStatement
("select * from admin where username=? and password=?");
ps.setString(1, username);
ps.setString(2, password);
ResultSet rs =ps.executeQuery();
s = rs.next();
}catch(Exception e)
{
e.printStackTrace();
}
return s;
}
请在问题 – GurV
中发布错误的完整堆栈跟踪任何人如果可以帮助我请 – user7331740
这个问题是在我的网站,因为我把2名称中必须删除名称=“签名”在2个输入,这是好的 – user7331740