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



Home Answers Viewqa JSP-Servlet Servlet-JSP population
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Kiran
Servlet-JSP population
0 Answer(s)      4 years and 5 months ago
Posted in : JSP-Servlet


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>

Advertisement
View Answers

Related Tutorials/Questions & Answers:
Servlet-JSP population - JSP-Servlet
Servlet-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-Servlet
Servlet-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-Servlet
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... in I redirect to a JSP page which populates a list of items available
Servlet-JSP population - JSP-Servlet
Servlet-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
Delhi Population by District
Delhi 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
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
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
java (servlet) - JSP-Servlet
java (servlet)  how can i disable back button in brower while using servlet or JSP
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
servlet - JSP-Servlet
servlet  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
atm code in servlet& jsp
atm 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 - JSP-Servlet
servlet/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
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 write the coding for converting the database data for example population into any type of graph using jsp and servlets?//
for converting the database data for example population into any type of graph using jsp and servlets pls help me out how to write the coding for converting the database data for example population into any type of graph using jsp and servlet
servlet - JSP-Servlet
Inserting 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-Servlet
About 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 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
Servlet & Jsp - Java Interview Questions
Servlet & 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
Servlet & Jsp - Java Interview Questions
Servlet & 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
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
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
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
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
Servlet - JSP Programming - JSP-Servlet
Servlet - 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
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
Servlet-JSP Mapping - JSP-Servlet
Servlet-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-Servlet
Servlet-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-Servlet
Distribute 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
Override any method in servlet or jsp - JSP-Servlet
Override any method in servlet or jsp   Hi Friend, Can we override any life cycle methods in servlet and jsp.  Hi Please click on this url: http://www.roseindia.net/jsp/simple-jsp-example
 

 

 

DMCA.com