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
Related Tutorials/Questions & Answers:
Using Servlets, JSP for Online ShoppingUsing 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
Advertisements
online test project on java using servlets and jsponline 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 projectonline 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-Servletonline 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-Servletonline 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 shoppingonline shopping hi, i am doing
online shopping project i want to do
online payment. How it can be possible
online shopping - Java Beginnersonline 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 Beginnersonline 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 projectonline 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
Register page using servlets,jsp and java beansRegister 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 portalonline 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 architectureusing 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 PortalOnline 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 PortalOnline 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 projectonline 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-ServletWriting 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
jsp -servletsjsp -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 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-Servletjsp 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 - JDBConline 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
jsp and servletsjsp 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 servletsjsp 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
JSP-Servlets-JDBCJSP-
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-ServletServlets 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-Servletjsp,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-ServletServlets 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-Servletservlets 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