Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Sonal jain
userloginmid.jsp
1 Answer(s)      2 years and 5 months ago
Posted in : JSP-Interview Questions


where is the userloginmid.jsp code?


Advertisement
View Answers

April 6, 2012 at 11:56 AM


userloginmid.jsp:

<%@ page import="java.sql.*,java.util.*,java.text.*,java.text.SimpleDateFormat" %>
<%

  String userName = request.getParameter("userName");
  String password = request.getParameter("password");

    System.out.println("MySQL Connect Example.");
    Connection conn = null;
    String url = "jdbc:mysql://localhost:3306/";
    String dbName = "user_register";
    String driver = "com.mysql.jdbc.Driver";
    String username = "root"; 
    String userPassword = "root";

      java.util.Date now = new java.util.Date();
      String DATE_FORMAT = "yyyy-MM-dd hh:mm:ss";
      SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);

    String strDateNew = sdf.format(now) ;


    try {
      Class.forName(driver).newInstance();
      conn = DriverManager.getConnection(url+dbName,username,userPassword);
      Statement st = conn.createStatement();
      String strQuery = "select * from userregister where username='"+userName+"' and password='"+password+"'"; 
      //out.println(strQuery);
      ResultSet rs = st.executeQuery(strQuery);

       if(rs.next())
        {

            int userid=rs.getInt(1);
            String user=rs.getString(2);

            session.setAttribute("userid",userid);
            session.setAttribute("username",user);
            session.setAttribute("intime",strDateNew);

            String queryString = "INSERT INTO admin set userid="+userid+",intime='"+strDateNew+"'";
            int i = st.executeUpdate(queryString);

            if(i>0)
            {
                response.sendRedirect("welcome.jsp");
            }

        }

        response.sendRedirect("login.jsp");
        conn.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
 %>

You can also find the above jsp code either by downloading source code of the following jsp application link:

http://www.roseindia.net/jsp/loginstatus.shtml

or through the following link

http://www.roseindia.net/jsp/javascriptpagerefresh.shtml



Related Tutorials/Questions & Answers:
userloginmid.jsp
userloginmid.jsp   where is the userloginmid.jsp code?   userloginmid.jsp: <%@ page import="java.sql.*,java.util.*,java.text.*,java.text.SimpleDateFormat" %> <% String userName = request.getParameter
Record user login and logout timing In JSP
;userloginmid.jsp", "welcome.jsp","logout.jsp" and "...;loginform" method="post" action="userloginmid.jsp"
Advertisements
How To Page Refresh Using JavaScript In JSP
="userloginmid.jsp" url=url+"?username="+username+"&...;   Step 3:Create a web page (userloginmid.jsp) to retieve
ma access reading values
="userloginmid.jsp" url=url+"?username="+username+"&password
ma access reading values
="userloginmid.jsp" url=url+"?username="+username+"&password
ms access
="userloginmid.jsp" url=url+"?username="+username+"&password="+password
ms access
="userloginmid.jsp" url=url+"?username="+username+"&password="+password
ms access
="userloginmid.jsp" url=url+"?username="+username+"&password="+password
ms access
="userloginmid.jsp" url=url+"?username="+username+"&password="+password
 

 

 

DMCA.com