Solved

JSP input , Java processing

Posted on 2003-10-22
8
211 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
  • 2
  • 2
  • 2
8 Comments
 
LVL 14

Accepted Solution

by:
kennethxu earned 63 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 62 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
getting param value 7 51
authenticate preemptively soap ui option 3 108
dateFashion java challenge 9 128
caughtSpeeding java challenge 16 132
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
Moving applications to the cloud or switching services to cloud-based ones, is a stressful job.  Here's how you can make it easier.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now