Solved

JSP input , Java processing

Posted on 2003-10-22
8
216 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 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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

With the rising number of cyber attacks in recent years, keeping your personal data safe has become more important than ever. The tips outlined in this article will help you keep your identitfy safe.
A look at what happened in the Verizon cloud breach.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

624 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