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



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ndemuweda
Using Servlets, JSP for Online Shopping
3 Answer(s)      2 years and 6 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);
    }
}

}


Advertisement
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
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 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  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
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
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
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 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 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
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 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 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
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
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 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
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
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
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
Advertisements
 

 

 

DMCA.com