1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

netbeans Q

Discussion in 'Java' started by mariamMAB, Mar 13, 2012.

  1. mariamMAB

    mariamMAB New Member

    Joined:
    Feb 27, 2012
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    Hi,
    This is my index.jsp page
    HTML:
    <body>
            <h1>Login: </h1>
            <form name="myForm" action="getPassword" method="POST">
                Name <input type="text" name="uName" value="" /><br />
                Password: <input type="password" name="uPass" value="" /><br />
               Address <input type="text" name="uAddress" value="" /><br />
                Phone <input type="text" name="uPhone" value="" /><br />
                Email <input type="text" name="uEmail" value="" /><br />
            
                <input type="submit" name="btSubmit" value="Send" />
            </form>
    
        </body>
    
    >>>>>and this is my servlet <<<<<
    Code:
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
             String uPhone = request.getParameter("uPhone");
             String uEmail= request.getParameter("uEmail");
            
            if(uPhone ?????????){
                RequestDispatcher dispatcher =
                getServletContext().getRequestDispatcher("/Correct.jsp");
                dispatcher.forward(request, response);
                 return;
                
                
            }else{
                RequestDispatcher dispatcher =
                getServletContext().getRequestDispatcher("/Wrong.jsp");
                dispatcher.forward(request, response);
            return;
            }
    
    >>>
    I want to A Servlet that:
    - checks the phone number has only numbers and no characters
    - checks if the email address has '@' (at) symbol and a '.' (dot) in it

    What should I wrote in ???? place
     
    Last edited by a moderator: Mar 13, 2012
  2. mariamMAB

    mariamMAB New Member

    Joined:
    Feb 27, 2012
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    Oh lazy people I already found the answer for the first part which is the phone, I will write it just in case someone will use it:

    PHP:
    protected void processRequest(HttpServletRequest requestHttpServletResponse response)
                
    throws ServletExceptionIOException {
            
    response.setContentType("text/html;charset=UTF-8");
            
    PrintWriter out response.getWriter();
            
             
    String uPhone request.getParameter("uPhone");
             
    String uEmailrequest.getParameter("uEmail");
            
            
           
            
    char[] chars = new char[uPhone.length()];
            
    uPhone.getChars(0chars.lengthchars0);
            for (
    int i 0chars.lengthi++) {
              if (!(
    '0' <= chars[i] && chars[i] <= '9')) {
                
    RequestDispatcher dispatcher =
                
    getServletContext().getRequestDispatcher("/Wrong.jsp");
                
    dispatcher.forward(requestresponse);
                
              }
              
            }
            
    RequestDispatcher dispatcher =
                
    getServletContext().getRequestDispatcher("/Correct.jsp");
                
    dispatcher.forward(requestresponse);
                 
        }
     
  3. mariamMAB

    mariamMAB New Member

    Joined:
    Feb 27, 2012
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    but please I need the solution for the other part which is E-mail validity check
     

Share This Page