Home Answers Viewqa JSP-Servlet Using Servlets, JSP for Online Shopping

 
 


Ndemuweda
Using Servlets, JSP for Online Shopping
3 Answer(s)      11 months ago
Posted in : JSP-Servlet

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 Pages:
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 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 - 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
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 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 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 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
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
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 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
What is shopping cart?
shopping cart software for selling their products online. What is shopping... online shopping site and start selling products online...What is shopping cart? In this tutorial we will understand the shopping cart
jsp code for shopping cart
jsp code for shopping cart  please provide me the jsp code for online shopping cart
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
online shopping
online shopping  hi, i am doing online shopping project i want to do online payment. How it can be possible
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
servlets
://www.roseindia.net/jsp/jspcookies.shtml http://www.roseindia.net/servlets/use... regarding the user usage and habits. Servlets sends cookies to the browser client using the HTTP response headers. When client gets the cookie information it?s
servlets
functionality to the servlets apart from processing request and response paradigm... application, and they can be applied to any resources like HTML, graphics, a JSP page... of filters. A filter is configured in a web.xml file. The class using
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
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
Shopping Cart,Shopping Cart software
gateway for all kinds of transaction online. The shopping cart software provides... their shopping.  Payment processing - Manages online credit card payments... Shopping Cart      
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
Servlets Books
, conference speaker on servlets and JSP (JavaOne, International Conference for Java... Programming, Core Servlets and JavaServer Pages (JSP), and More Servlets and JavaServer Pages (JSP) from Sun Microsystems Press. Core Servlets and JavaServer Pages
Free Java Shopping Cart,Shopping cart Application
; Shopping Cart allows the web site owner to setup online store so that visitors can buy the product online. In other words, it assists online shopping customers... basic information about shopping cart and the software that help online
To create a shopping cart
To create a shopping cart  I want to create a online shopping cart using struts and hibernate. I created my first page. Now i want to provide hyperlink to the product like(apparel,jewellery,foods,utensils) and i want to display
Shopping cart
but it provides a secure gateway for all kinds of transaction online. The shopping... sensitive data. Shopping cart software are usually implemented by using HTTP cookies... Shopping cart Overview A web based shopping cart is something
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
Shopping Cart
of online store it is the software for collecting the shopping items online... of online shopping many companies have developed shopping cart software with many...Shopping Cart Shopping cart is also know as trolley, carriage, buggy or wagon
Shopping Cart Features
Ideal Requirements Of Shopping Cart Most of the people think to use a shopping cart for their online store will run their business. But it is far from truth. Using an shopping cart for your e-commerce site (Online Store) is just
jsp online ex
jsp online ex  plz help me providing source code for mini project online exam using jsp and mysql..... plzplz plzhelp me pur
servlets
servlets  why we are using servlets
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
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
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
servlets
servlets  How do you communicate between the servlets?   We can communicate between servlets by using RequestDespatcher interface and servlet chaining
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
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
read XML file and display it using java servlets
read XML file and display it using java servlets  sir, i can't access...-fold> } jsp: <%@page contentType="text/html"%> <%@page pageEncoding... library. --%> <%-- <%@taglib uri="http://java.sun.com/jsp/jstl/core
servlets - JSP-Servlet
an application using Servlets or jsp make the directory structure given below link http://www.roseindia.net/servlets/directory-structure.shtml Now visit
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
servlets
servlets  How to open and read the contents of a text file in servlets?   Please visit the following link: Read text file using Servlet
servlets - JSP-Servlet
servlets  i need a help to write a program on employee details using servlets.  Hi friend, employee form in servlets...;This is servlets code. package javacode; import java.io.*; import java.sql.
servlets
are the differ ways you can communicat between servlets   Different ways of communicating between servlets:- 1)Using RequestDispatcher object. 2)Sharing resource using ServletContext object. 3)Include response of the resource
servlets and jsp - JDBC
servlets and jsp  I want to display textboxes dynamically in my page using JSP and servlets (javascript for validation). For eg, consider the recruitment application form for various jobs. The name, address and tel

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.