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.

Ads









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
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
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
online shopping  hi, i am doing online shopping project i want to do online payment. How it can be possible
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
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  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
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
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
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 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
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 MYSQL Database with JSP & Servlets.
Using MYSQL Database with JSP & Servlets.  ... acceres the MYSQL database. Here I am using MYSQL & tomcat server...=password Typing help on the mysql prompt shows online help
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
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
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
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
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
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

Ads