NEWBIE - creating a simple JSP login page

Hi guys,
I am really really stuck, and I would be so grateful if you guys could help me in any way. I am creating a simple application, but as part of the application i have to create a login / logout sub-application. It needs to verify the username and password by looking up a database in mySQL. I've had a look around on the internet to see if there is any simple way of doing it, but i can't understand most of it. I'm really new to JSP and only know how to do simple statement like <c:choose> and stuff like that. If anyone can help me in any way to create as simple a login / logout application that verifies the username and password from a database, I would be ever so grateful, thank you!
Just to let you know, the security-roles and all that stuff together with the <tomcat-users> stuff has already been set up.
I found this code by the author brain.compression, which seems to very useful, I've not tried it out yet, but was wondering, if somebody could help me split the code up into the separate JSP pages i will need, as I am not too sure which bits of the code need to go on what pages.
Thank you to anyone that can help me out and thanks for brain.compression for providing this code. I'm sorry for posting this in a forum not related to JSP, its just that I am a complete newbie to JSP and nobody in that forum is helping me.
brain.compression's code starts here...
First for the page you are requesting you would need a verify if the user is logged in or not:
<c:if test="${existingUser==null}">
<jsp:forward page="login.jsp">
<jsp:param name="origURL" value="${pageContext.request.requestURL}"/>
<jsp:param name="errorMsg" value="Please log in first" />
</jsp:forward>
</c:if>
This will redirect you to the login page:
<font color="red">
${fn:escapeXml(param.errorMsg)}
</p>
</font>
<form method="post" action="authenticate.jsp">
<table>
<tr>
<td>Please Enter the following information to log in:</td>
</tr>
</table>
<table>
<tr>
<td>User ID:</td>
<td><input name="userid" value="${fn:escapeXml(cookie.userid.value)}"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" value="${fn:escapeXml(cookie.password.value)}"></td>
</tr>
</table>
After that you have to verify with your DB if the login info provided is correct:
%-- Removing any scoped variables --%>
<c:remove var="existingUser" />
<c:if test ="${empty param.userid || empty param.password}" >
<c:redirect url="login.jsp">
<c:param name="errorMsg" value="Please enter a User Id and Password." />
</c:redirect>
</c:if>
<%-- Checking if User Id and Password are valid --%>
<sql:query var="anyvariable" dataSource="${data}">
SELECT * FROM table WHERE user_id = ? AND pass = ?
<sql:param value="${param.userid}"/>
<sql:param value="${param.password}"/>
</sql:query>
<c:if test="${anyvariable.rowCount == 0}">
<c:redirect url="login.jsp">
<c:param name="errorMsg" value="Invalid User Id or Password"/>
</c:redirect>
</c:if>
Also can somebody tell me if i am right. Do I need to create a page called login.jsp to put the actual form on, and a page called authenticate.jsp to verify the username and password are correct? Finally i see that brain.compression has used a variable called existingUser but has he actually declared it anywhere. Thanks again for anybody that can help me out!

i am still a jsp noobie but i have done some applications using html javascript php asp and other languages. What you want to do is take the data from the login form then compare that to the db see if it actually exist and has the correct info. From there you want to write a cookie to the users computer to hold the username and password, which will be checked for at the begining of every page verifying it in the database. This is how i have done password verification in the past and it works fairly well and unless your server gets hacked your pages should be secure.

Similar Messages

  • JSP Login Page is slow in 11.5.10.2

    Hi,
    JSP Login Page is slow in 11.5.10.2 . But If we login through form login (dev60cgi/f60cgi).
    Forms are working fine, No issue from the DB Side.
    We have bounce the Apache and clear the cache as well , but no luck.
    Pls give us some pointer on this.
    Regards,

    Hi,
    It is a clone Instance..Did you review the log files?
    I have one doubt.. If we have lacs record in WF_NOTIFICATION..will the performace get impact bcz of this.It may have an impact on the performance, but I believe it should not affect the main login page.
    Regards,
    Hussein

  • Create a simple JSP

    hi everybody
    how can I create a simple jsp?
    what should I write into portalapp.xml???

    Hi,
    have a look here:
    [SAP J2EE Development Tutorials|http://www.sdn.sap.com/irj/sdn/javaee5?rid=/webcontent/uuid/28b1ed0e-0d01-0010-c887-a8fdecdb9053#section9 [original link is broken]]
    There are some examples for developing simple JSPs...
    Regards

  • New to jsp, login page errors

    Hi
    I'm totally new to using jsp and as part of a project I need to create a login page which compares the
    entered email and password with those contained in a database.
    I've created the java code and jsp pages, there's no obvious errors (to me anyway) but everytime I try to run it I get the same error.
    The code for the login page is:
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <body>
    <form action="validate.jsp" method="POST">
    email address - <input type="text" name="emailAddress">
    <br>
    password - <input type="password" name="passWord">
    <input type="submit" value="Submit">
    <input type="reset" value="Reset">
    </form>
    <br>
    new customer? To sign up <a href="new%20customer.jsp">Click here</a>
    </body>
    </html>The validation page code is:
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@page import="java.util.*" %>
    <jsp:useBean id="idHandler" class="org.login" scope="request">
        <jsp:setProperty name="idHandler" property="*"/>
    </jsp:useBean>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <body>
                <%
                String username=(String) session.getAttribute("username");
                String password = (String) session.getAttribute("password");
                String emailAddress = request.getParameter("emailAddress");
                String passWord = request.getParameter("passWord");
                if (idHandler.authenticate(emailAddress, passWord)) {
                    response.sendRedirect("index.jsp");
                } else {
                    response.sendRedirect("login.jsp");
                %>
        </body>
        </head>
    </html>and the java code is:
    package org;
    import java.io.IOException;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.sql.DataSource;
    public class login {
        private DataSource getJdbcConnectionPool() throws NamingException {
            Context c = new InitialContext();
            return (DataSource) c.lookup("java:comp/env/jdbc/connectionPool");
    //method that is called from validateuser.jsp and this checks for the authentic user and
        public boolean authenticate(String emailAdd, String pass)
                throws SQLException, IOException, IOException, NamingException {
            String emailAddress = null, Password = null;
            // connection instance
            Connection connection = null;
            try {
                DataSource dataSource = getJdbcConnectionPool();
                connection = dataSource.getConnection();
                String sql = "SELECT emailAdd, pword FROM customer WHERE emailAdd='" + emailAdd + "'" + "AND pword='" + pass + "'";
                PreparedStatement ps = connection.prepareStatement(sql);
                ResultSet rs = ps.executeQuery();
                if (rs.next()) {
                    emailAddress = rs.getString("emailAdd");
                    Password = rs.getString("pword");
                if (emailAddress != null && Password != null && emailAddress.equals(emailAddress) && pass.equals(Password)) {
                    return true;
                } else {
                    return false;
            }finally  {
                // close the connection so it can be returned to
                // the connection pool then return the list           
                connection.close();
    }finally the error message I get is:
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException
         org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:460)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    root cause
    java.lang.NullPointerException
         org.login.authenticate(login.java:56)
         org.apache.jsp.validate_jsp._jspService(validate_jsp.java:76)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.26 logs.
    help?

    login.java:56 is:
    connection.close();right? So, it looks like the call to getJdbcConnectionPool within authenticate throws an exception and control is passed to the finally block where connection is still null, resulting in the NPE. You should probably catch any exceptions thrown by the lookup for your datasource so you can see what the "real' error is.

  • How can i create a simple netweaver portal page that shows text and images?

    Hi,
    i have a simple question or maybe it's not so simple.
    I am completly new to SAP Netweaver 2004s Portal. At the moment i'm trying to understand the struture of the whole thing. I already know how to create roles, worksets and pages and i know how to combine the different elements so a user can acces them.
    And now i want to create a simple portal page that shows text and images. Is it possible to create such a simple page with the portal content studio? What iView do i have to use?
    (I just want to create a start page with a welcome text on it.)

    Marc
    Considering that you would any ways go ahead with complex development from this simple start page I recommend create a Web dynpro Iview for your start page (include the Iview in your page).
    For putting the contents use Netweaver Developer studio to build a simple start page application and put your static text on that Iview.
    Please go through the following log after your NWDS development is over - This will make you comfortable for further challenging work.
    http://help.sap.com/saphelp_erp2005/helpdata/en/b7/ca934257a5c96ae10000000a155106/frameset.htm
    Do reward points if this helps and let me know of you want anything more.

  • Creating a simple JSP

    Hi.
    I am new to JSP technology. I want to start by developing a simple JSP. I want to create a form that has some Ten input fields. User inputs the values and submits the form. On sibmit, the form is stored as a document. Next, the manager (listed on the form as one of the field) willl access the document ans he will either accept the application or he will rejects it. On each of these events - submit, accept and reject some back end data will be updated.
    Could any one help me in starting this? Any links to a sample code would greatly help me.
    Thanks & regards,
    Sanjay.

    here you go http://www.geocities.com/topjavalinks/

  • How to: create a Login page with data tags

    hi, how could i create a jsp login page using the data tags.. and how to associate it with the other jsp pages that should be displayed in case of the correct insertion of the password .

    http://technet.oracle.com:89/ubb/Forum2/HTML/006025.html

  • How to create a login page....

    Hey guys....i am working on a erm applocation....i want to create a pop up login page for my application....please tell me how to do it....

    J2EE allows you to declaratively manage security. And you're mixing up two different things, either you want a dialog box for logging in ( known as BASIC authentication ) or you want a login page ( known as FORM based authentication ). Both are easily swappable with minimum effort.
    Take a look at Chapter 32 here: https://java.sun.com/j2ee/1.4/docs/tutorial/doc/
    And Google J2EE security example/ tutorial/ whatever, you'll find lots of resources. If you have specific queries, you can always post it here in the forums

  • Problems with compilation of a Simple JSP

    Hello!
    This is a typical newbie problem with starting off on JDeveloper 3.0 (JDK 1.1.8) and Oracle 8i (8.1.1). When I create a simple JSP (The "Hello World" Jsp given in the File | New | Web Objects option) and try to run it - it gives me the following error :
    java.io.IOException CreateProcess : cmd.exe /C start "" "C:\PROGRAM FILES\ORACLE\JDEVELOPER 3.0\myprojects\WebAppRunner.html" error = 0
    Obviously the JSP does not run.
    Any pointers about what might be wrong?
    Regards
    Mona

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Mona Marathe ([email protected]):
    Hello!
    This is a typical newbie problem with starting off on JDeveloper 3.0 (JDK 1.1.8) and Oracle 8i (8.1.1). When I create a simple JSP (The "Hello World" Jsp given in the File | New | Web Objects option) and try to run it - it gives me the following error :
    java.io.IOException CreateProcess : cmd.exe /C start "" "C:\PROGRAM FILES\ORACLE\JDEVELOPER 3.0\myprojects\WebAppRunner.html" error = 0
    Obviously the JSP does not run.
    Any pointers about what might be wrong?
    Regards
    Mona<HR></BLOCKQUOTE>
    The above error message is likely due
    to JDeveloper looking for the NT command
    interpreter named CMD.EXE .
    I was able to run servlets with JDeveloper
    and Windows 98 by copying COMMAND.COM to
    C:\CMD.EXE, which was much easier to do
    than putting a new OS on my machine.
    Cheers,
    David

  • Which jar file is required for jsp dynpro page programming ?

    Hi all:
       I use NWDS wizard to create one small jsp dynpro page application. However the project has some errors, it said "
    This compilation unit indirectly references the missing type com.sapportals.htmlb.page.DynPage (typically some required class file is referencing a type outside the classpath)     Test1.java     NewParProject1/src.core/com/xinao/test     line 0
    " However, I found the class DynPage is not found in current project.
    I have already added com.sap.portal.htmlb_api.jar into my project.
    Where can I locate and find that jar file (which include the DynPage class ) ?

    Hi,
      Refer the following link content. It has answer to your question.
      class path incomplete at first portal component project
    Rds,
    Shanthakumar.
    points r welcome.

  • Help with simple jsp please

    Hi,
    I would like to know how to create a simple jsp to display some data from the database. I was able to create a bean to display the data from a table using the wizard. How do I put this bean's content into the jsp?
    Thanks,
    Charles Li

    Even better are the online tutorials that will take you step by step:
    http://www.oracle.com/technology/obe/obe9051jdev/index.htm
    Try the ADF Workshop one - it will show you most of what you need.

  • Reset Button @ login page

    Good Morning,
    I would like to know how to create reset button in login page.
    Thanks in advance,
    NY APEX

    Sorry to jump on someone else's post It's best to start a new thread, you can always reference this post in your question
    but I am very interested in the point you raise "you have other options... database" - can you kindly explain how you could utilise a database to replace standard OBIEE user security - or point me at a reference on how to do this.See Oracle Business Intelligence Server Administration Guide http://download.oracle.com/docs/cd/E10415_01/doc/bi.1013/b31770.pdf chapter 15 - Security in Oracle BI, in particular p.326 "Setting Up External Table Authentication"

  • Create login page using jsp, servlet  & Oracle

    hi,
    i need the sample application for creating login page using jsp, servlet & Oracle,can you please post one sample application.
    thanks
    sona

    See
    http://www.oracle.com/technology/products/jdev/collateral/papers/10g/adfstrutsj2eesec.pdf
    Frank

  • WebCenter RIDC DataControl always redirects any JSP page to login page

    Hi
    I have created a Data Control which connects to the UCM data repository and created a plain JSP page to return the results. I have used RIDC Connection settings and authentication details are tested and they look fine to me.
    RIDC Socket Type: socket
    Server Host Name: localhost
    Content Server Listener Port: 4444
    Authentication: Identity Propagation
    Username/Password: weblogic/weblogic
    But when ever I ran the test JSP page, it always redirects the page to login page. For example: http://127.0.0.1:7101/RIDCDocumentManager-Portal-context-root/faces/oracle/webcenter/portalapp/pages/login.jsp
    Any suggestions?
    Thanks
    Khad

    Thanks for the details Yannick. The home.jspx works as expected. Thanks for that.
    I have got one more question on passing username through RIDC api.
    Via RIDC, how can I pass the UserName to the IdcContext object dynamically [IdcContext userContext = new IdcContext("weblogic");]. I mean how to retrieve the logged in user name for the person requesting the page instead of hardcoding the username. Below is the code fragment:
    // create the manager
    IdcClientManager manager = new IdcClientManager();
    // build a client that will communicate using the intradoc protocol
    IdcClient idcClient = manager.createClient("idc://localhost:4444");
    // get the config object and set properties
    idcClient.getConfig().setSocketTimeout(30000); // 30 seconds
    idcClient.getConfig().setConnectionSize(20); // 20 connections
    //create a simple identity with no password (for idc:// urls)
    IdcContext userContext = new IdcContext("weblogic");
    // create an identity with a password
    //IdcContext userPasswordContext = new IdcContext("weblogic", "idc");
    // get the binder
    DataBinder binder = idcClient.createBinder();
    // populate the binder with the parameters
    binder.putLocal("IdcService", "GET_SEARCH_RESULTS");
    //binder.putLocal("QueryText", parameter);
    parameter = getInputParameter();
    binder.putLocal("QueryText", "<qsch>" + parameter + "</qsch>");
    binder.putLocal("ResultCount", "20");
    // execute the request
    ServiceResponse response = idcClient.sendRequest(userContext, binder);
    // get the binder
    DataBinder serverBinder = response.getResponseAsBinder();
    DataResultSet resultSet = serverBinder.getResultSet("SearchResults");
    // loop over the results
    for (DataObject dataObject : resultSet.getRows())
    dataObject.get("dDocTitle");
    dataObject.get("dDocAuthor");
    dataObject.get("dInDate");
    System.out.println("Title is: " + dataObject.get("dDocTitle"));
    System.out.println("Author is: " + dataObject.get("dDocAuthor"));
    System.out.println("Author is: " + dataObject.get("dInDate"));
    }

  • How to create a login page for my client and a form so he can add/edit or delete information ?

    I have a real state client and one of the pages is to show all the houses he is selling with their information.
    And he wants to have a login page so that only him have permission to add, edit or delete a house from his web page.
    Also when adding a new house i want to have a form(kinda like craigslist, ebay,amazon) so he can chose type of house,price,adress,  floor, used , new, etc...?
    I hope i was specif enough.
    thanks

    If this was me, I would just create a log in page. Set the users default access level to 0 and then go into the database and set your's to 1. From there, I would have a page that only is accessable to people with a user access level > 0 .
    On this second page, make a table where you can insert picture(s) of the house, as well as information about the house. Have this page insert records into a database.
    Finally, you will have your house listing on a page that is a dynamic table, which populates itself from the database of housing pictures and information.
    It involves some database work, but with the built in functions of Dreamweaver, it is simple. I would suggest however, that you store links to the pictures in your database as opposed to storing the actual picture, but that's more up to you.
    By doing all this, you have made it so at any time, your admin, and only the admin, can log in, upload pictures and information about a listing, and have it go live to the site.

Maybe you are looking for

  • Lost/stolen iphone 5, what happens to my imessage accounts on my other devices?

    I have lost/had stolen my iphone 5 and will have to therefore get it replaced. As it may well have been stolen I think I am going to erase all the data on the phone via the 'find my iphone' app. My first question is, having erased the data on the pho

  • Open Sequence Dialog and TestStand2.0

    Hello, I am trying to set the default search directory in Open sequnce File Dialog.vi. I see that there is a place where you can input the initial path, and this is exactly what I want. I have looked in the online help and it appears I am using it co

  • Multiple websites and applications using one user database

    I've got several applications and websites that will be built around one main application. In a perfect situation users will be able to register once and be able to log into the different applications and websites using that single account. The diffe

  • E-Recruitment external job posting

    Hi All In E-Recruitment i need to display the list of job requirements in external site ( monster,jobpost etc) from the external site if user clicks on the job requirement i need to take him to the portal Please let me know is this possible in portal

  • Software Developer / Cyber Security

    Moderator edit - content deleted, not in accordance with forum guidelines. zantzz - your interest is appreciated, but this forum is not the appropriate place for your request. Tom K. Closed.