Servlet-JSP population
Hi
I have a login page which accepts inputs and take to a servlet, servlet makes a jdbc connection to oracle server to validate the login and password.
I have got all this right. once he gets logged in I redirect to a JSP page which populates a list of items available at that time in the data base. I'm getting redirected to the jsp page but my list is not being populated, my code is as shown below I have included all the jars. Do i need to close the connection? the connection is made and the validation of username and password is working fine. my table cartlist has rows in it.I checked it.
Servlet Code:
----------------------------------------------
package com.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Date;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Myservlet
*/
public class My extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public My() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//PrintWriter pw = response.getWriter();
//response.setContentType("text/HTML");
//Date today = new Date();
//pw.println("<b>"+today+"</b>");
String s = request.getParameter("username").toString();
String p = request.getParameter("pwpassword").toString();
Connection connection;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
String serverName = "127.0.0.1";
String portNumber = "1521";
String sid = "orcl";
String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
String username = "scott"; String password = "tiger";
connection = DriverManager.getConnection(url, username, password);
Statement statement = connection.createStatement() ;
ResultSet rs = statement.executeQuery("select * from Login");
while (rs.next()){
String a = rs.getString(1);
String b = rs.getString(2);
if (s.equals(a)&& p.equals(b)){
RequestDispatcher rd;
rd = request.getRequestDispatcher("/cartupdate.jsp");
rd.forward(request,response);} }
}catch (Exception ex){
ex.printStackTrace();
}
}
}
JSP CODE:
----------------------------------------------------------------
<html>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<head>
<title>cartupdate</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<%@ include file="header.jsp"%>
<%@ include file="left.jsp"%>
<style>
div.form {
float: center;
width: 30%;
height:50%;
margin-right: auto;
}
</style>
<form method="post" action="updateCart">
<%
Class.forName("oracle.jdbc.driver.OracleDriver");
String serverName = "127.0.0.1";
String portNumber = "1521";
String sid = "orcl";
String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
String username = "scott"; String password = "tiger";
Connection connection = DriverManager.getConnection(url, username, password);
Statement statement = connection.createStatement() ;
ResultSet rs = statement.executeQuery("select * from cartlist");
int i=1;%>
<TABLE cellpadding="5" border="1">
<tr>
<td> </td>
<td>Item</td>
<td>Price</td>
<td>Units</td>
</tr><%
while (rs.next()){ %>
<tr><td><input type="checkbox" name="box<%=i%>"/></td>
<td><input type="text" name="itemname<%=i%>" value="<%=rs.getString(1)%>"/></td>
<td><input type="text" name="itemname<%=i%>" value="<%=rs.getString(2)%>"/></td>
<td><input type="text" name="number<%=i%>"/></td>
</tr>
<%}%>
</table>
<p><input type="submit" name="direction" value="Add2Cart">
<input type="submit" name="direction" value="checkout1"><b>Click checkout once you Add2Cart</b> </p>
<p><br></p>
<p></p>
</form>
</body>
</html>
View Answers
Related Tutorials/Questions & Answers:
Servlet-JSP population - JSP-ServletServlet-
JSP population Hi,
I got my code worked. now I have another task. My
jsp page on submit gets redirected to another
servlet update cart... with textfields also.
how the loop in the
servlet should go to check all the boxes
Servlet-JSP population - JSP-ServletServlet-
JSP population Hi,
this is regarding my previous question... and display in the next page.
I changed my
servlet code something like this but i find some problem retrieving the values from the
jsp page. As my cart in
jsp Advertisements
Servlet-JSP population - JSP-ServletServlet-
JSP population In refernce to this Question
http://www.roseindia.net/answers/viewanswers/9843.html
I reduced my
servlet code and
JSP... in my
jsp page my code is working fine. If I dont check any of the item in my
Servlet-JSP population - JSP-ServletServlet-
JSP population Hi
I have a login page which accepts inputs and take to a
servlet,
servlet makes a jdbc connection to oracle server... in I redirect to a
JSP page which populates a list of items available
servlet - JSP-Servlet be the xml code which will describe a
servlet and mapps an instance of it with specific url..??? Hi friend,
Servlet and
JSP Examples.
Servlet and
JSP Examples
atm code in servlet& jspatm code in
servlet& jsp pls send me the code of ATM project in
servlet jsp .
my requirements are first of all an user login window open then balance enquiry, withdraw of money, money transfer, then log out.
pls send as early
servlet - JSP-Servletservlet please post me some attractive learn simple steps tutoriols jsp&servlet with source code or example with netbeans.
post all
servlet and
jsp simple example chapter by chapter who will build
my knowldge very fastly
servlet/jsp - JSP-Servletservlet/jsp hi,
get me the source code to upload all file formats in
servlet/
jsp
plaese help me as soon as possible its urgent!!!
by
saravanan.k Hi friend,
Code to help in solving the problem
servlet - JSP-ServletInserting values in
servlet and jsp How to Insert the values into database table using
Servlet and
JSP? Insert the values into database table using
Servlet and JSP.Code ExampleDataInsertionExam.javaimport java.io.
About jsp and Servlet - JSP-ServletAbout
jsp and Servlet Servlets are directly using java technologies. It is used in HTTP,FTP..etc, But
Jsp only used in HTTP. Servlets are running fastly... Then why we moved from
Servlet to
JSP.. Pl Tell me the reasons
How to pass an arraylist from servlet to jsp?How to pass an arraylist from
servlet to
jsp? Hello,
Can anyone please tell me how to pass an arraylist from
servlet to
jsp? I have two arraylist...
servlet to
jsp?
Thanks in advance
Difference Between Servlet and JSPDifference Between
Servlet and
JSP
In this section we will describe the
Servlet and
JSP. We will compare the
both technologies. We will discuss the differences between
Servlet and
JSP.
Servlet
Servlet is a Java class that is usually
Servlet & Jsp - Java Interview QuestionsServlet & Jsp how to forward or redirect the client request from
servlet to
jsp? how a thread or request pass from one
servlet prog to one
jsp prog? is it possible of communicating from
servlet to
jsp prog? please explain
Servlet & Jsp - Java Interview QuestionsServlet & Jsp is it possible of communicating from
SERVLET to
JSP...
servlet to
jsp.
Servlet2.java:
import java.io.*;
import javax.servlet...."))){
String
jsp = "./
jsp/loginSuccess.jsp";
RequestDispatcher dispatcher
JSP with java/servlet - JSP-Servlet (java bean or
servlet) to fecth the database.
Jsp would get the data from.../
servlet-
jsp-data-list.shtml
Hope that it will be helpful for you.
Thanks...
JSP with java/servlet Thanks Deepak for your answere to my previous
Crop image Using JQuery, servlet or JSP.Crop image Using JQuery,
servlet or
JSP. Hi sir
I need the code of Cropping image using JQuery with the help of
servlet or
JSP. I need both the code Client side as well as of server side.
Please Help me
How to pass multiple values from a servlet to JSP?How to pass multiple values from a
servlet to
JSP? hi, I want to pass multiple values form a
servlet to
JSP.
Hw do i do that?
I am able to send one value at a time without any prb, but I am unable to carry multiple (from two
Java servlet with jsp on sql serverJava
servlet with
jsp on sql server How to delete a user by an admin with check box in Java
Servlet with
jsp on Sql Server?
Here is a
jsp example that can delete the multiple record from the database by selecting
Servlet - JSP Programming - JSP-ServletServlet -
JSP Programming Hi,
I'm writing a
jsp page as shown... to cart or checkout). I'm programming in a
servlet getting the input parameters...
servlet code is also pasted below. please let me know how to solve
Servlet-JSP Mapping - JSP-ServletServlet-
JSP Mapping Dear Sir,
My Query were:
How I use the issueData() in
Jsp which define in
Servlet_Two.java.
If any mistake in my code please...\.wlnotdelete\extract\myserver_ProjDemo_ProjDemo\
jsp_
servlet\__issue.java' failed
Servlet-JSP Mapping - JSP-ServletServlet-
JSP Mapping Dear Sir,
My Query were:
How I use the issueData() in
Jsp which define in
Servlet_Two.java.
If any mistake in my code please...\.wlnotdelete\extract\myserver_ProjDemo_ProjDemo\
jsp_
servlet\__issue.java' failed
Distribute Servlet or JSP on network - JSP-ServletDistribute
Servlet or
JSP on network Sir
Even after successfully deploying a
servlet or
JSP program on J2EE web server I am not been able..."
For any more problem on
Servlet and
Jsp visit to :
http://www.roseindia.net
Delhi Population by DistrictDelhi
Population by District
Are you looking for the District wise
population... stay in the Delhi and
this way the
population of Delhi is growing day-by-day.
Due to good job opportunities and high living standards the
population of
Delhi
ArrayList from JSP to Servlet - JSP-Servlet in a scriplet in a
jsp page. how can i access the arraylist in a
servlet which... should it be declared in
jsp and in
servlet. do i need to do any casting...://www.roseindia.net/
jsp/
servlet-
jsp-data-list.shtml
Hope that it will be helpful for you
which version of eclipse is used to execute Servlet or JSP Servlet or
JSP. previosuly i installed eclipse 3.1 .i am having j2se 5.0 with which i...which version of eclipse is used to execute
Servlet or JSP Hi
Can...
JSP or Servlets with the help of Eclipse.Another point is that when i installed
servlet and jspservlet and jsp how to connect an
jsp and an
servlet without connecting to database
Servlet,JspServlet,Jsp This is my requirement?I have a login page and register page?If I give the url as http://localhost:8080/Project/Login.jsp ,it should go to login page?.then from login page on click of register button I can register
servlet and jspservlet and jsp how can i get a form question from a database... with servlets and
jspīs
Have a look at the following links:
http://www.roseindia.net/
jsp/paging.shtml
http://www.roseindia.net/
jsp/navigation
SERVLET AND JSPSERVLET AND JSP If i want tio create a login form using SUBMIT,ADD...;For more information visit the following links:
http://www.roseindia.net/
jsp/user...://www.roseindia.net/answers/viewqa/
JSP-Servlet/16413-using-insert-and-delete-in-a-single
SERVLET AND JSPSERVLET AND JSP If i want tio create a login form using SUBMIT,ADD...;For more information visit the following links:
http://www.roseindia.net/
jsp/user...://www.roseindia.net/answers/viewqa/
JSP-Servlet/16413-using-insert-and-delete-in-a-single
Fetching database field from servlet to jsp page ?Fetching database field from
servlet to
jsp page ? Hello Java... field.
I wanted to pass some of the database field from
servlet to
jsp...
(i am opening my database in
servlet init() method )
how to pass rs.getString(8
population problem plz help me befor 16 March 2011 !!population problem plz help me befor 16 March 2011 !! the
Q is :
How can i count how many years it will take for the
population of a town to go over...
population :" );
Scanner keyboard = new Scanner (System.in);
popu = keyboard.nextInt
jsp/servlet - JSP-Servletjsp/servlet How to create and save the excel file on given location using
jsp/
servlet? hi Geetanjali,
Read for more information,
http://www.roseindia.net/
jsp/poi/excelPOI.shtml
Thanks
EJB and Servlet - JSP-ServletEJB and Servlet hi all;
I Have some Question regarding the
EJB and
servlet,
How can we communicates
servlet and EJB?
can u give me a sample Code how to connect
my
servlet to ejb..
ty
Hi Friend
servlet - JSP-Servletservlet http://localhost:8080/collegeapp/Avanthi.html
after complition of my
servlet program, i typed in the above url, then
small window is displayed in my monitor, it asks connect to localhost,
enter user name