0

i am beginner in java, i am trying to display user name with image jsp page when loging with email id...
plllsssss help me out...

package User_pack;

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;
import java.sql.*;
import DB.DBCon;
import javax.servlet.http.HttpSession;
import javax.servlet.RequestDispatcher;


public class Validate extends HttpServlet {

    Connection con=null;
    Statement st=null;
    ResultSet rs=null;
    String sql=null,email,pass,user,img;
    boolean flag;
    protected void login(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out=response.getWriter();
       try
       {
            HttpSession sess=request.getSession();
          email=request.getParameter("useremail");
          pass=request.getParameter("password");

           //out.print(username+","+pass);
         con=DBCon.getCon();
         out.print("h");
         st=con.createStatement();
         sql="select email,password,image from reg where Email='"+ email+"'";
         out.print("h");
         rs=st.executeQuery(sql);
         out.print("h");
         while(rs.next())
         {
           out.print("h");  
            flag=false;
         out.print(flag);
             if(email.equals(rs.getString(1))&& pass.equals(rs.getString(2)))
             {
             out.print(flag);

                 sess.setAttribute("mail", email);

               flag=true;  

               out.print(flag);
             }
         }
         check(request,response);
       }
       catch(SQLException ex)
       {
           ex.printStackTrace();
       }
    }



     public void check(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
     {
         try
         {
        if(flag)
        {


           RequestDispatcher rd=request.getRequestDispatcher("/Zid.jsp");

           rd.forward(request, response);
        }
        else
        {
          RequestDispatcher rd=request.getRequestDispatcher("/Err1.jsp");
           rd.forward(request, response);  
        }
     }
         catch(Exception ex)
         {
             ex.printStackTrace();
         }
     }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        login(request, response);
    }


    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
2
Contributors
1
Reply
8
Views
2 Years
Discussion Span
Last Post by Taywin
0

Is this an assignment? I hope so because the code indicates that passwords are saved in PLAIN TEXT in the database! Also, the code is comparing email & password both in case-sensitive.

Anyway, you simply print out the HTML image tag, but the url needs to be dynamic. Look at the comment in the reply post here

Edited by Taywin

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.