-2

私を助けてください 。サーブレットを使用してフォームを検証する方法。私はすべてのサーブレットを実行しましたが、何も機能しません。私のコンセプトは、フィールドが null/empty の場合、登録フォームにリダイレクトされることを意味します。それ以外の場合は、データベースで更新されます

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>Insert title here</title>
    </head>
    <body bgcolor="##09874##">
        <form method="post" action="insertData">  
            Employee id <input type="text" name="username" value=""><br><br>
            Password   <input type="password" name="password" value=""><br><br>
            Confirm Password   <input type="password" name="cpassword" value=""><br><br>
            <input type="submit" value="Submit">
        </form>
    </body>
</html>
4

1 に答える 1

-1

サーブレットで request.getParameter を使用し、if else 条件を作成し、request.requestdispatcher. を使用してユーザーの詳細を確認します jsp を使用し、dttails が正しい場合、requestdispatcher は正しい jsp に送信し、詳細が空または間違っている場合は送信できますjspを修正するには...私はJavaでも新しい私を助けようとしています。次に例を示します。

public class FirstServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");  
PrintWriter out = response.getWriter();  

String n=request.getParameter("username");  
String p=request.getParameter("userpass");  

if(LoginDao.validate(n, p)){  
    RequestDispatcher rd=request.getRequestDispatcher("servlet2");  
    rd.forward(request,response);  
}  
else{  
    out.print("Sorry username or password error");  
    RequestDispatcher rd=request.getRequestDispatcher("index.html");  
    rd.include(request,response);  
}  

out.close();  
} 
于 2013-11-07T20:40:06.033 に答える