Solved

JSP input , Java processing

Posted on 2003-10-22
8
212 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem with Pie chart in Jsp 20 215
jason format for rest webservices and sub resourcing 1 89
spring AOP 6 85
servlet cookie finding by name 1 79
Employees depend heavily on their PCs, and new threats like ransomware make it even more critical to protect their important data.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 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