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



Home Answers Viewqa JSP-Servlet failure to log in
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


boifang
failure to log in
1 Answer(s)      3 years and 9 months ago
Posted in : JSP-Servlet


<blockquote>
  <p>Blockquote</p>
</blockquote>

<p>&lt;%@page contentType="text/html"%>
&lt;%@page pageEncoding="UTF-8"%>
&lt;%@page import="java.sql.Connection" %>
&lt;%@page import="java.sql.DriverManager" %>
&lt;%@page import="java.sql.Statement" %>
&lt;%@page import="java.sql.ResultSet" %>
&lt;%@page import="java.sql.PreparedStatement" %>
&lt;%@page import="java.sql.SQLException" %></p>

<p><html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Login</title>
    </head>
    &lt;%
        String userName = request.getParameter("username");
        String password = request.getParameter("password");
        String rm<em>me = request.getParameter("rm</em>me");
        String rm<em>uname = request.getParameter("rm</em>uname");</p>

<pre class="prettyprint">    if (userName != null &amp;&amp; password != null) {
        if (rm_me != null) {
            Cookie ckU = new Cookie("username", userName);
            Cookie ckP = new Cookie("password", password);
                   response.addCookie(ckP);
        } else {
            if (rm_uname != null) {
                Cookie ckU = new Cookie("username", userName);

            }
        }

        try {

        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

            Connection conn = DriverManager.getConnection("jdbc:odbc:mydsn","sa","password@123");

            String sql = "select customer_id, fname, lname, email_id, phone_number from customer_details where user_name=? and password=?";
            PreparedStatement stmt;

            ResultSet rs = stmt.executeQuery();

            if (rs.next()) {
                session.setAttribute("customerId", rs.getString(1));
                session.setAttribute("userName", userName);
                session.setAttribute("fName", rs.getString(2));
                session.setAttribute("lName", rs.getString(3));
                session.setAttribute("emailId", rs.getString(4));
                session.setAttribute("phoneNumber", rs.getString(5));
                conn.close();
          %&gt;
                &lt;jsp:forward page="welcome.jsp" /&gt;
          &lt;%} else {%&gt;


        Sorry! You have entered an invalid username or password. Please try again.
          &lt;%}
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
%&gt;
&lt;body&gt;
    &lt;p&gt; &lt;/p&gt;
    &lt;p&gt; &lt;/p&gt;
    &lt;p&gt; &lt;/p&gt;
    &lt;p&gt; &lt;/p&gt;

    &lt;%
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (int i = 0; i &lt; cookies.length; i++) {
            if (cookies[i].getName().equals("username")) {
                userName = cookies[i].getValue();
            }
            if (cookies[i].getName().equals("password")) {
                password = cookies[i].getValue();
            }
        }
    }
    %&gt;

    &lt;form name="LoginForm" id="LoginForm" method=post Action="login.jsp"&gt;
        &lt;table width="70%" align="center" border="1"&gt;

            &lt;tr&gt;
                &lt;td&gt;&lt;img src="logo.jpg"&gt;&lt;/img&gt;&lt;/td&gt;
                &lt;td&gt;Lets conserve our environment&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td align="center"&gt;User Name&lt;/td&gt;
                &lt;td&gt;&lt;input type="text" name="username" maxlength="50" value="&lt;%=(userName==null?"":userName)%&gt;"/&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td align="center"&gt;Password&lt;/td&gt;
                &lt;td&gt;&lt;input type="password" name="password" maxlength="100" value="&lt;%=(password==null?"":password)%&gt;"/&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt; &lt;/td&gt;
                &lt;td&gt;
                    &lt;input type="submit" name ="login" value="Login" /&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td align="center"&gt;
                    &lt;input type="checkbox"  name="rm_uname" value="RememberUsername" /&gt;Remember Username
                &lt;/td&gt;
                &lt;td&gt;
                    &lt;input type="checkbox"  name="rm_me" value="RememberMe" /&gt;Remember Me
                &lt;/td&gt;
            &lt;/tr&gt;
        &lt;/table&gt;
    &lt;/form&gt;
&lt;/body&gt;
</code></pre>

<p></html></p>

<blockquote>
  <p>Blockquote</p>
</blockquote>

<p>can someone help to identify the error because even when the username and password are provided the error message appers indicating failure to loggin. </p>

Advertisement
View Answers

Related Tutorials/Questions & Answers:
failure to log in
failure to log in  <blockquote> <p>Blockquote</p> </blockquote> <p>&lt;%@page contentType="text/html"%>... failure to loggin. </p>   Please visit the following links: http
log in
log in  sir i designed one login.jsp page with one form, username,login,and one submit button .if i enter username and password its been verify the mydatabase in in table in the field of username and password while it s correct
Advertisements
build failure error with maven
build failure error with maven  hi, when i clean install a maven file I am getting the error in command prompt like sun.misc.BASE64Encoder is Sun proprietary API and may be removed in a future release. There are several
Log-in Valdidation
Log-in Valdidation  how to create login validation in jsp
log out
log out  how do i create a log out on a project without it exiting system so it does not reload again
Describe the effects of a server failure on the application
Describe the effects of a server failure on the application Prev  Chapter 7. Validate, tune and troubleshoot... Describe the effects of a server failure on the application
log 4j
log 4j  what is log4j? can you give me clear information about log4j?   Please go through the following link: log4j Tutorials
error log
error log  hi my requirement is validate xml and xsd in java.If there is an errors then i will log error and store into error table. so plz if any one knows send code urgent. error table details-------------- Table
log in page
log in page  hi all i want to create a login page in jsp which should be validated using ajax. please help me dong that with code...   Here is a jsp example that accepts username and password from the user and check
Writing Log Records to a Log File
Writing Log Records to a Log File       This section demonstrates for writing log records to a log file. Logger provides different types of level like: warning, info
com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Communications link failure due to underlying exception
com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Communications link failure due to underlying exception  Hi, In my application...: com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Communications link failure due to underlying exception: Tell me how
user log in according to their role
user log in according to their role  i want a jsp code for different users log in to different pages according to their role.example normal user and administrator. normal user for user page and administrator for admin page
user log in according to their role
user log in according to their role  i want a jsp code for different users log in to different pages according to their role.example normal user and administrator. normal user for user page and administrator for admin page
error log and send Database
error log and send Database  hi my requirement is validate xml and xsd in java.If there is an errors then i will log error and store into error table. so plz if any one knows send code urgent. error table details
if my database(oracle) connection failure means wat is the code to write in exception ?
if my database(oracle) connection failure means wat is the code to write in exception ?  if my database(oracle) connection failure means wat is the code to write in exception
Error in log file
Error in log file  Hi, I AM using Apache tomcat 6.0.16 server... of executing project i get following errors in "Apache Tomcat 6.0.16 log". Apr 17, 2011 11:57:57 AM org.apache.catalina.core.ApplicationContext log INFO: Marking
Error in log file
Error in log file  Hi, I AM using Apache tomcat 6.0.16 server... of executing project i get following errors in "Apache Tomcat 6.0.16 log". Apr 17, 2011 11:57:57 AM org.apache.catalina.core.ApplicationContext log INFO: Marking
Error in log file
Error in log file  Hi, I AM using Apache tomcat 6.0.16 server... of executing project i get following errors in "Apache Tomcat 6.0.16 log". Apr 17, 2011 11:57:57 AM org.apache.catalina.core.ApplicationContext log INFO: Marking
keeping log of page load - Java Beginners
to keep a log of if the page has succesfuuly loaded or not. It means I want to keep log for sucess and failure both for page loading. Can you please give me some...keeping log of page load  Hello, I have a project and I need
How to detect system failure using java code - Java Beginners
How to detect system failure using java code  I am doing a project... to detect the process that make failure. I have no idea about the project so please help me. And i need some site to download java source code
JSP cannot log to FileAppender - Log4J
JSP cannot log to FileAppender  Hi, Thank you for your attention... method. But when the LogClass is called from jsp file, no log file is created... ----------------------------------------------------------------------------- ### direct log messages to stdout
Dealing with negative lat/log numbers
Dealing with negative lat/log numbers  I need to run a script that will return cities that match within a certain range of the latitude and longitude. We are trying to check to make sure what we return for lat/log matches close
Creating a log in a text file - Applet
Creating a log in a text file  Hey there, I have created an applet that supports 4 different languages, and the applet needs to be runnable... that keeps a log of the time of when the application is run and closed, every
Log In Form Validations - Java Beginners
Log In Form Validations  Good Morning Sir ,I have Created Log in Form with Databse Connectivity and i have took two JTextFields 1)USERNAME 2)password if two Jtextfields are blanks i want to show msg blank Username
Where is servlet log file in net beans?
Where is servlet log file in net beans?  When you use context.log("some string"); then the string get written into the servlet log file. But where is the servlet log file in netbeans? I am using netbeans 6.9. I can't locate
Redirect the log used by DriverManager and JDBC driver
Redirect the log used by DriverManager and JDBC driver  How can I get or redirect the log used by DriverManager and JDBC drivers
Write to the log used by DriverManager and JDBC drivers.
Write to the log used by DriverManager and JDBC drivers.  How can I write to the log used by DriverManager and JDBC drivers
Use Log in Servlet Context
Use Log in Servlet Context       This section illustrates you how to use log in Servlet Context. We.... The method context.log() writes the specified message to a servlet log file
Context Log Example Using Servlet
Context Log Example Using Servlet  ... of Context Log in servlet. Context Log is used to write specified message to server log file when servlet is called. In the following JSP page (message.jsp) we
Limiting the Size of a Log File in Java
Limiting the Size of a Log File in Java  ... to limit the size of a log file in Java. Log files haven't any boundation at the file creation time but Java provides the facility for limiting the size of a log
Java error log
Java error log       Java error log is a error that arises due to internal error. A error logger is simple an object that is used to show an error log message
Advertisements
 

 

 

DMCA.com