Solved

JSP input , Java processing

Posted on 2003-10-22
8
214 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
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 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
netstat -a in AIX unix 8 51
Running Java Servlet inside Eclipse Luna 6 168
Why my table column Id is not passed to java object? 4 46
iterator/ListIterator approach 17 52
While it may be true that the internet is a place of possibilities, it is also a hostile environment lurking with many dangers. By clicking on the wrong link, trusting the wrong person or using a weak password, you are virtually inviting hackers to …
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

740 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