jsp+servlet进行表单验证,但是点击提交按钮时显示空白页面
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class zc extends HttpServlet {
/**
* Constructor of the object.
*/
public zc() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
//response.setContentType("text/html");
PrintWriter out = response.getWriter();
String name=request.getParameter("name");
String pwd=request.getParameter("pwd");
System.out.println("jjj");
if(name=="admin"&&pwd=="123"){
//request.getRequestDispatcher("ok.jsp").forward(request, response);
response.sendRedirect("ok.jsp");
}
}
/**
* Returns information about the servlet, such as
* author, version, and copyright.
*
* @return String information about this servlet
*/
public String getServletInfo() {
return "This is my default servlet created by Eclipse";
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
[解决办法]
System.out.println("jjj");
if(name=="admin"&&pwd=="123"){
//request.getRequestDispatcher("ok.jsp").forward(request, response);
response.sendRedirect("ok.jsp");
}
1控制台有没输出jjj
如果没有,问题去代码上面找
如果有,试一下"admin".equals(name)的用法
再一个,没有写else对应的jsp页面,写一个看看