Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JSP input , Java processing

Posted on 2003-10-22
8
Medium Priority
?
217 Views
Last Modified: 2010-05-18
I am trying to input data in a JSP page and on clicking "Sumbit" button would like to write the data into a database. Whats the most easiest way to do this. Do I have to follow a servlet approach or can I do it without involving servlets. Can anyone provide a sample code for a JSP input page, and a java class to write it to the database without involving servlets? Really appreciate all the help
0
Comment
Question by:Aryaan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
8 Comments
 
LVL 14

Accepted Solution

by:
kennethxu earned 252 total points
ID: 9604420
1. you use any html form submit data to a servlet or jsp, it is strongly recommended to use servlet to handle data access, but yes, you can do without servlet.

2. in the servlet or jsp page, you use jdbc programming write data into database, jdbc tutorial:
http://java.sun.com/docs/books/tutorial/jdbc/basics/

example:
<form method=post action=dbwrite.jsp>
<input type=text name=mydata>
<input type=submit>
</form>
<%@ page import="java.sql.*" %>
<%
  Class.forName( "your.jdbc.driver" );
  Connection con = null;    
  Statement stmt = null;
  try {
    con = DriverManager.getConnection("your-jdbc-url");
    stmt = con.createStatement();
    String queryString  =("insert into mytable values( '" + request.getParameter( "mydata" ) + "' )" );
    stmt.executeUpdate(queryString);
  }
  finally {
    if( stmt != null ) try { stmt.close(); } catch (Exception e) { e.printStackTrace(); }
    if( con != null ) try { con.close(); } catch (Exception e) { e.printStackTrace(); }
  }
%>
0
 

Author Comment

by:Aryaan
ID: 9611026
Ok...How do I do it with a Servlet approach. My project is like this: There is a welcome page that has two links. One for New Customer and one for Existing Customer. WHen the the user clicks on New, a jsp page opens that has the textfields for the user input and when the user presses the submit button, these values get written into the database. When the user clicks on the Existing link, a jsp opens that has a few textfields for doing searches. The user can enter the last name and press Submit button and the details from the database are printed out. Can anyone provide me a sample of what the JSP and the servlet should look like? Thanks for your help.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9611739
sorry, we cannot do homework project for you. the information we provided is enough for you to start. please try it you.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Aryaan
ID: 9615030
I just said sample code. I am not asking anyone to do it for me. Thanks for your help anyways.
0
 
LVL 3

Assisted Solution

by:applekanna
applekanna earned 248 total points
ID: 9624608
This shud be simple
Check this out and c if you are able to figure it out.

http://www.sylistron.org/tutorial/jdbc/getting.html

Also technically speaking JSP = servlets

If u need more help mail again
0
 
LVL 3

Expert Comment

by:applekanna
ID: 9624618
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
Are you an Exchange administrator employed with an organization? And, have you encountered a corrupt Exchange database due to which you are not able to open its EDB file. This article will explain all the steps to repair corrupt Exchange database.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question