Using Servlets, JSP for Online Shopping

Using Servlets, JSP for Online Shopping

What is wrong with my code ?

JSP

<form action="LoginServlet "method="post" >
<table>

     <tr ><td>Username:</td><td><input type="text" name="Id" ></td></tr>
     <tr><td>Password:</td><td><input type="Password" name="password"></td></tr>
     <tr><td></td><td><input type="reset" value="Clear"></td></tr>
     <tr ><td></td><td><input type="submit" value="Submit"></td></tr>

  </table>
</form>

Servlet

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String Id = request.getParameter("Id");
    String password = request.getParameter("password");
    String userType = request.getParameter("userType");
    HttpSession session = request.getSession();

    Enumeration headerNames = request.getHeaderNames();

    while (headerNames.hasMoreElements()) {

        String headerName = (String) headerNames.nextElement();
        System.out.println("Header Name: " + headerName + ",  passed value is: " + request.getHeader(headerName));
        System.out.println("<br>");
    }
    if (!Id.equals("") && Id != null) {
        session.setAttribute("savedId", Id);


        if (session.isNew()) {
            System.out.println("You have created a session! ");
        } else {
            System.out.println("Session already created ");
        }


        System.out.println("<html>");
        System.out.println("<head>");
        System.out.println("<title>Servlet LoginServlet</title>");
        System.out.println("</head>");
        System.out.println("<body>");
        LoginService loginService = new LoginService();


        boolean result = loginService.authentication(Id, password, userType);
        if (result) {
            if (userType.equals("admin")) {

                response.sendRedirect("adminPage.jsp");

            } else {
                response.sendRedirect("viewCart.jsp");

            }

        } else {
            response.sendRedirect("Login.jsp");

            System.out.println("<h1>Halo! " + Id + " We Know you are" + userType + "</h1>");
            System.out.println("</body>");
            System.out.println("</html>");



            System.out.close();
        }
        processRequest(request, response);
    }
}

}

View Answers

June 11, 2012 at 11:35 AM

Login.jsp:

<form action="LoginServlet "method="post" >
<table>
     <tr ><td>Username:</td><td><input type="text" name="Id" ></td></tr>
     <tr><td>Password:</td><td><input type="Password" name="password"></td></tr>
     <tr><td>User Type:</td><td><input type="text" name="userType"></td></tr>
     <tr><td></td><td><input type="reset" value="Clear"></td></tr>
     <tr ><td></td><td><input type="submit" value="Submit"></td></tr>
</table>
</form>

LoginServlet.java:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class LoginServlet extends HttpServlet{ 
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException{

    String Id = request.getParameter("Id");
    String password = request.getParameter("password");
    String userType = request.getParameter("userType");
    HttpSession session = request.getSession();

    Enumeration headerNames = request.getHeaderNames();

    while (headerNames.hasMoreElements()) {

        String headerName = (String) headerNames.nextElement();
        System.out.println("Header Name: " + headerName + ",  passed value is: " + request.getHeader(headerName));
        System.out.println("<br>");
    }
    if(!Id.equals("") && Id != null) {
        session.setAttribute("savedId", Id);

        if(session.isNew()) {
            System.out.println("You have created a session! ");
        }else {
            System.out.println("Session already created ");
        }
        System.out.println("<html>");
        System.out.println("<head>");
        System.out.println("<title>Servlet LoginServlet</title>");
        System.out.println("</head>");
        System.out.println("<body>");
        LoginService loginService = new LoginService();

        boolean result = loginService.authentication(Id, password, userType);
        if (result) {
            if (userType.equals("admin")) {

                response.sendRedirect("adminPage.jsp");

            } else {
                response.sendRedirect("viewCart.jsp");

            }

        } else {
            response.sendRedirect("Login.jsp");

            System.out.println("<h1>Halo! " + Id + " We Know you are" + userType + "</h1>");
            System.out.println("</body>");
            System.out.println("</html>");
            System.out.println();
        }
        processRequest(request, response);
    }
}

}

June 11, 2012 at 11:41 AM

The above code accepts username, password and user type from the user. If the user enters admin, then the page sends the request to adminPage.jsp. Otherwise it sends the request back to the login.jsp.


June 11, 2012 at 11:52 PM

Thank you.









Related Tutorials/Questions & Answers:
Using Servlets, JSP for Online Shopping
Using Servlets, JSP for Online Shopping  What is wrong with my code ? JSP <form action="LoginServlet "method="post" > <table> <tr ><td>Username:</td><td><input type="text" name="Id
online shopping code using jsp
online shopping code using jsp  plz send me the code of online shopping using jsp or jdbc or servlets plz plz help me
Advertisements
online test project on java using servlets and jsp
online test project on java using servlets and jsp  as i am doing online test project on java using jsp and servlets ,,,the problem is in the code of jsp file which i have sent,...,i used next and previous buttons and used two
online shopping cart complete coding in pure jsp
online shopping cart complete coding in pure jsp  online shopping cart complete coding in pure jsp   Please visit the following link: JSP Online shopping cart
online shopping project
online shopping project  sir, plz can u send me the coding of simple application of online shopping cart project using jsp and servlets which should be run in netbeans without any errors
online shopping project in j2ee - JSP-Servlet
online shopping project in j2ee  hello, I am making a project online shopping using jsp-servlet. I wanted to know that how do I implement following: 1) A non-registered user(or a registered user who has not signed-in) can browse
online shopping project in j2ee - JSP-Servlet
online shopping project in j2ee  hello, I am doing a project on online shopping implementing it with only jsp-servlet.I wanted to know that do I need... might not notice) or just the servlet-jsp is enough?? Thanks in advance
online shopping
online shopping   Hai sir/madam, i'm working on online shopping project.requirements is oracle10g,servlets/jsp... what is the difference b/w storing and saving image into database.how to store and how
online shopping
online shopping  hi, i am doing online shopping project i want to do online payment. How it can be possible
online shopping - Java Beginners
online shopping  Respected Sir, Sir please help me how to handle online shooping and shopping cart by click on image by only using jsp
online shopping - Java Beginners
online shopping  Respected Sir, Sir please help me how to handle online shooping and shopping cart by click on image by only using jsp?   Hi friend, For solving the problem visit to : http
online shopping project
online shopping project  can you plz send the source code of online shopping application developed with the help of struts 1.2, hibernate and sql , jsp   Please visit the following link: Struts Shopping Cart
jsp code for shopping cart
jsp code for shopping cart  please provide me the jsp code for online shopping cart
online test software using jsp and servlet
online test software using jsp and servlet  online test software using jsp and servlet
online shopping project
online shopping project  Hi, i want online shopping project modules description and screens
online shopping project
online shopping project  Hi, i want online shopping project modules description and screens
courier management service (using servlets,jsp,jdbc)
courier management service (using servlets,jsp,jdbc)   is anyone having information about courier management service ? plz share it .its urgent THANKING YOU IN ADVANCE
Register page using servlets,jsp and java beans
Register page using servlets,jsp and java beans  i want code for register page using jsp,serlets and java beans.iam getting error for my code in java...://www.roseindia.net/jsp/user-registration-form-using-jsp.shtml Thanks
online shopping portal
online shopping portal   Blockquote Scenario: Online Shopping Portal XYZ.com wants to create an online shopping portal for managing its... first before they do shopping using the shopping portal. However, everyone
using jsp and servlets andin Mvc architecture
using jsp and servlets andin Mvc architecture  how to insert a form data in different tables, that means education details in education table, address details in address table,like that and finally if we fetch all must come
Online Shopping Portal for xyz.com
Online Shopping Portal for xyz.com  XYZ.com wants to create an online shopping portal for managing its registered customers and their shopping. The customers need to register themselves first before they do shopping using
Online Shopping Portal for xyz.com
Online Shopping Portal for xyz.com  XYZ.com wants to create an online shopping portal for managing its registered customers and their shopping. The customers need to register themselves first before they do shopping using
Online Shopping Portal
Online Shopping Portal  XYZ.com wants to create an online shopping... need to register themselves first before they do shopping using the shopping... their dream of having an online shopping portal? Steps to be followed Create
Online Shopping Portal
Online Shopping Portal  XYZ.com wants to create an online shopping... need to register themselves first before they do shopping using the shopping... help XYZ.com to realize their dream of having an online shopping portal? Steps
using servlets and jsp technologies search the documents - Development process
using servlets and jsp technologies search the documents   write a program to develop search contents,uploading data and advance searching options using servlets and jsp with source code
online shopping project
online shopping project  dear sir/madam,i am uday pratap singh. i need online shopping project description with code. i also want which type of question arises in interview from the current project. please send detail about
Writing a file using servlets - JSP-Servlet
Writing a file using servlets  I'm using a servlet to read an input from a jsp file and write into a .txt file in my computer. The code is good until reading the data and creating a file in my space. but it is not writing
How to export web page to excel using java or jsp or servlets
How to export web page to excel using java or jsp or servlets  Hi I am trying to export web page(jsp page ) to excel using jsp or servlets. I am... errors. Please can anyone tell me how to do this using java or jsp or servlets
code to send sms alerts using jsp online
code to send sms alerts using jsp online  I am new to mobile aplication development. pls send me the code for sms alerts after clicking the button
need a sample project using java technologies like jsp, servlets, struts
need a sample project using java technologies like jsp, servlets, struts  Hi everybody! I have learnt core java,jdbc,jsp,servlets & struts... other project with detailed explanation using the above technologies by which i
jsp -servlets
jsp -servlets  i have servlets s1 in this servlets i have created emplooyee object, other servlets is s2, then how can we find employee information in s2 servlets
online bookstore - JSP-Servlet
online bookstore  i want to display some books like online shoping.please send me code for that using jsp and servlets
Using MYSQL Database with JSP & Servlets.
Using MYSQL Database with JSP & Servlets.  ... acceres the MYSQL database. Here I am using MYSQL & tomcat server... on the mysql prompt shows online help.   mysql> help
jsp shopping cart - JSP-Servlet
jsp shopping cart  i develope the online shopping project. but in that i require the code for how to insert a item into cart and also delete from it and how could I add more than one item into the cart. please give me an idea
online shopping project in java - JDBC
online shopping project in java  hii, i am doing a project online shopping in JSP-SERVLET.I wanted to know that i need 2 use images which will be retrieved through oracle 10g. 1) what is the best strategy for storing
Need Help in creating online quiz application using JSP - JSP-Servlet
Need Help in creating online quiz application using JSP  Hi, i am creating online Quiz application using JSP and MySQl ,Apache 6 in Netbeans IDE. i..., JSP Page Online Quize Application
Upload CSV File into Columns of sql table using servlets and jsp
Upload CSV File into Columns of sql table using servlets and jsp  Hello sir, plz give me the code to upload csv file data into respective columns of table
How to Upload a file directly to Oracle database using JSP or Servlets?
How to Upload a file directly to Oracle database using JSP or Servlets?  Hi I want to upload a file(csv or excel) to Oracle 10g Database using JSP, here is my code which gives me an error.. Addfile.jsp <%@ page import
online shopping project report with source code in java
online shopping project report with source code in java  Dear Sir/Mam, i want to a project in java with source code and report project name online shopping. thank you
jsp and servlets
jsp and servlets  what is difference between jsp and servlet?? what should a person use to develop website ??   JSP is used for view in MVC... the request submitted from browser and process the data and redirect it to JSP
Online Shopping Cart Solutions
There are different shopping cart solutions available to suite different online stores.... The custom shopping cart development enhances the quality of your online store... has ranges of features making online shopping easy for the customer. If you want
jsp and servlets
jsp and servlets  i want code for remember password and forget password so please send as early as possible ............. thanks in advance   Please visit the following link: http://www.roseindia.net/jsf/richfaces
how to write the coding for converting the database data for example population into any type of graph using jsp and servlets?//
for converting the database data for example population into any type of graph using jsp and servlets pls help me out how to write the coding for converting the database data for example population into any type of graph using jsp and servlet
how do i provide down a pdf document fecility on my web page using jsp and servlets?
this program by using jsp-servlets. any one can help me please?? Thanks&...how do i provide down a pdf document fecility on my web page using jsp and servlets?  Hai, I need a program to provide download option for pdf file
JSP-Servlets-JDBC
JSP-Servlets-JDBC  Hi all, 1, Create - i want sample code... should be retrieved in JSP and should be able to update using JSP and update..... It will be helpful if it's made into sub modules, JSP, Driver Constants, Servlets, Java Beans
Servlets Vs Jsp - JSP-Servlet
Servlets Vs Jsp  In servlets and Jsp's which one is important? and also tell me the Is Servlets are best or jsp's are best? give me the(reason also... with servlets but not with jsp's)Most of cases we use jsp's for presentation.i.e
jsp,servlets - JSP-Servlet
jsp,servlets   Good Afternoon Sir, I am sowmya i have a doubt that is whether it is possible to use arrays in servlets.how to declare that arrays in servlets and i am getting values from textbox in jsp
servlets - JSP-Servlet
servlets link . you can learn more information about servlets structure. To develop an application using servlet or jsp make the directory structure Read for more information. http://www.roseindia.net/servlets/directory
Servlets in JSF - JSP-Servlet
Servlets in JSF  Hi! I am using Java Visual Studio to develop my... in the form itself by double clicking why should i go for servlets to write code.... Simply what is the role of servlets in JSF. which one is the best one..jsp
servlets and jsp - JSP-Servlet
servlets and jsp  HELLO GOOD MORNING, PROCEDURE:HOW TO RUN A SERVLET AND JSP IN COMMANDPROMPT AND ALSO IN NETBEANS IDE6.0,IT'S VERY URGENT FOR ME,IN ADVANCE THANK U VERY MUCH.   TO Run Servlets in Compand

Ads