Servlet-JSP population

Ads
 

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>&nbsp</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

Ads









Related Tutorials/Questions & Answers:
How to call servlet in JSP?
How to call servlet in JSP?  How to call servlet in JSP
Servlet - JSP-Servlet
Servlet and Java Code  Example and source code in Servlet and JSP
Advertisements
What is the difference between JSF, Servlet and JSP?
What is the difference between JSF, Servlet and JSP?  What is the difference between JSF, Servlet and JSP
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 JSP
Difference 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
Java servlet with jsp on sql server
Java 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
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
How to carry multiple values from a Servlet to a JSP?
How to carry multiple values from a Servlet to a JSP?  By using the below code I am able to carry the username to a JSP (single value... needs to be carried from my servlet to a JSP. How do I do
servlet and jsp
servlet and jsp  how to connect an jsp and an servlet without connecting to database
Servlet,Jsp
Servlet,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 jsp
servlet 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 JSP
SERVLET 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 JSP
SERVLET 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
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
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
how do i upload a file by using servlet or jsp?
how do i upload a file by using servlet or jsp?  hi plz tell me the write java code
how to store data in other table using servlet and jsp
how to store data in other table using servlet and jsp  pls can anyone tell how to store data in other table using servlet and jsp and want to display that data too.and the data in first table must be same.pls help
How to display Jfreechart from servlet in jsp web page at specified location
How to display Jfreechart from servlet in jsp web page at specified... in Servlet which is in image format.plz sir give me the code to display this chart in jsp web page . Thank you very much Sir
ModuleNotFoundError: No module named 'ubi-population-tool'
ModuleNotFoundError: No module named 'ubi-population-tool'  Hi, My... named 'ubi-population-tool' How to remove the ModuleNotFoundError: No module named 'ubi-population-tool' error? Thanks   Hi
How to get the data from the database using Servlet or JSP program
How to get the data from the database using Servlet or JSP program  ... by using servlet or jsp program by typing the output as like this below.... Actual problem is that i have a simple program in jsp in the sense to get data
Servlet - JSP - JSP-Servlet
Servlet - JSP  Here is my complete code. all my code is running with out any error. the for loop in servlet is running as many times as my checkboxes... Servlet Code: ---------------------- package com.servlet; import
Servlet - JSP - JSP-Servlet
Servlet - JSP  i used arraylist in servlet as shown ArrayList total = new ArrayList (); ... total.add(k[i]); session.setAttribute("efg",total); when I code this like in my jsp <%ArrayList<Integer> data= new
servlet - JSP-Servlet
is my servlet program output,what is the solution...' ,you ve to set the path to servlet.jar or servlet-api.jar which is under common
Java Servlet - JSP-Servlet
Java Servlet   Hello Sir Could you help me in understanding directory Structure for servlet page in eclipse (IDE). I save my Sevlet in WEB-INF but it is not displaying, it is displaying code of servlet. Process used
Image retrieval in Servlet and JSP
Image retrieval in Servlet and JSP  Sir, How should i give dynamic paths to image in JSP. EX : `<img src="C:\Users\Public\Pictures\Sample Pictures\-------.jpg" alt="" name="image5" width="980" height="320" id="" />
How to pass and catch HTML parameters to a Java program using REST services?(without using servlet/jsp)
How to pass and catch HTML parameters to a Java program using REST services?(without using servlet/jsp)  Hello, I am new to these technologies i.e.... servlet/jsp). Also how to use hibernate criteria? Please help. Its very urgent
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without

Ads