Help with Servlets!!

Hi all,
I need help with Java and Jsp. Here are the specs:
1. An HTML web form that contains info about a customer: name, address, telephone number.
2. When the "Submit" button is clicked, the information will go directly into an Oracle database table named "customer".
Where should I start?? So far, I have created the HTML web form. So what i need is to write a servlet that will take the data from the web form and insert that into the Oracle table. If you have any solutions to my problem, please let me know. Thanks a lot in advance.

<%@ page language="java" import="java.sql.*" %>
<html>
<head>
<title>
Customer
</title>
</head>
<body>
<%!
java.sql.Connection con;
java.sql.PreparedStatement pstmt;
java.sql.ResultSet rs;
javax.servlet.http.HttpServlet request;
String name,address;
int phone;
int i;
%>
<%
     try {     
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = java.sql.DriverManager.getConnection
("jdbc:odbc:<DSN name>","scott","tiger");
%>
<% } catch(Exception e){ System.out.println(e.getMessage()); } %>
<%
name = request.getParameter("name");
address = request.getParameter("address");
phone = Integer.parseInt(request.getParameter("phone"));
pstmt=con.prepareStatement("insert into <table name> values(?,?,?)");
pstmt.setString(1,name);
pstmt.setString(2,address);
pstmt.setInt(3,phone);
i=pstmt.executeUpdate();
%>
</body>
</html>
1. create a dsn connecting oracle, using ODBC from control panel
2. name the text fields in the html page as "name","address","phone"
3. enter the table name you created in oracle in place of <table name>
I hope this should work , let me know .......
bye
vamsee

Similar Messages

  • Help with servlet

    I have a project with servlets in the 2 following folders
    myprojects and myclasses
    In my projects I have the helloProject and inside it I have the helloHtml folder and the helloPackage.
    So in the helloHtml folder I have the hello.html file and in the helloPackage I have the Hello.java (which is the servlet)
    when I compile this .java file the class file is inserted in the file myclasses\helloProject\helloPackage
    First in the file hello.html I have the code
    action="http://localhost:8080/servlet/helloPackage.Hello
    and so the servlet is executed fine.
    The problem is that I need to put a button in the code of Hello.java
    so that I can have reloaded the first page which is the hello.html
    But I am confused if I write onclick=history.go(-1) I have what I want but this page is not reloaded so I have some parameters there that I do not want
    Can I write sth like onclick=location.href=http://locahost:8080/.....??
    Could you please give me an advice considering the above description of my files??
    Thank tou very much....

    use sendRedircet(String AbsoluteURL) to send the Browser a redirect header so the browser send a new (fresh) request to the serlvet (with any parameter you specified).

  • Need Urgent Help with Servlets!!!

    I was just assigned a java project few days back and the thing is that i noe nuts abt JAVA!!! My first time and i admit i'm a slow learner.
    I was tasked to develop a servlet for web based query of inventory status in FIFO storage from QIS database.
    Basically, i heard according to my supervisor that this is a very simple project that may be completed in just days..but as i said this is my first Java program and i really need u guys to help me!!!! I have no idea how to start the entire coding process.
    The main page where the option buttons are is actually a form. This program have a HTTP extension i think. Below i have indicate the System and User Requirements.
    System Requirements
    * A Servlet
    * 2 option buttons
    * 1 for retrieving a Summarised Report
    * 1 for retriveving an Detailed Report
    * 1 command button for retrieval of data
    * Retrieved data will be displayed on another frame
    User Requirements
    * Be able to view Summarised Report at a click of a mouse
    * Be able to view Detailed Report also at a click of a mouse
    PLS HELP!!!!!!!!

    Justa comment...
    << according to my supervisor that this is a very simple project that may be completed in just days
    If your supervisor is so confident, then, maybe he/she should just get it done himself/herself. I really mean it. However, if that does happen, he/she should provide post-implementation support himslef/herself.
    In the meanwhile you can continue thinking about doing it the right way. Which is to first get some grasp of sorts about the various Java and other technologies and concepts you are talking about. Then have some kind of plan and follow it.
    I think at the end both you, and more importantly, your supervisor would see the difference in the result with respect to quality of work.
    Forums such as these provide an excellent wealth of information mostly because they are a means to consolidate knowledge gained by individuals from their past experience.
    However, in my opinion, it would be wrong to expect that one would be able to design and implement a real-life application just from information gathered from such forums. An example problem if you do it that way is: who will provide guaranteed support if something does not work in your real-life application. Your supervisor ?
    Instead, do the study part systematicaly. Try to convince your supervisor that thats the way to do it. Then do it. And come back with specific problems you might have.
    Best luck.

  • URGENT please help with servlets

    am using Jbuilder 3 and there is no servlet classs to import .imported JSDK and the javax files. but it keeps saying my class does not extend http servlet any ideas!!

    I've used JBuilder3 a few times and as far as I remember the default Target jdk (version 1.2) cannot be changed or ammended and so you can't really import javax.servlet stuff.
    Go to project -> properties.
    You probably just need to define a new jdk version call it "JDK 12 Servlets" or something. It'll prompt you most of the way and then you just need to edit the Class path and add the javax stuff.
    Alternatively you can just save the file with jbuilder and do the compiliation from the command line.
    Hope this helps.

  • Help with Servlet-RMI

    I am planning to write a servlet which communicates with another java processes via RMI. This is necessary because the java process will act as a server serving requests from the servlet which will pass results to the client. I am new to RMI and would appreciate very much if anyone can direct me to some examples, docs or recommend books (even better) which might help..........
    many thanks in advnace

    Hi DevMentee (nishil?)
    First many thanks and I am new to RMI and I did look
    at Sun and JGuru's RMI stuff on the web(good on theory
    but short on real world examples like stockquoteserver
    etc..).Perhaps these Web pages contain the type of examples you are looking for (assuming you are unfamiliar with them)
    http://www.javaworld.com/isearch?qt=RMI&x=56&y=11&site=javaworld&ms=1&tid=1&st=1&rf=0
    http://www.fawcette.com/Archives/premier/mgznarch/javapro/1998/jp_nov_98/th1198/th1198.asp
    http://www.fawcette.com/Archives/premier/mgznarch/javapro/1998/jp_febmar_98/rk0298/rk0298.asp
    Yours links they will be very helpful...is
    there a particular site you would recommend for
    examples etc?Personally I liked Dick Baldwin's tutorials, but each person is different -- that's why I gave a variety of resources. Hopefully one of them will be good for you.
    MY servers are in C++ on NT implemented using MS
    stuff, so perhaps CORBA would not be possible, but
    perhaps I can access using COM which could be easier
    than JNI...I remember seeing mention of a third-party COM-java bridge library, but I can't give you any details, sorry :-(
    ALSO, I have one more question :-)
    Is it possible to run multiple RMI servers (processes)
    on the same machine? if so what would happen if
    multiple requests came thru using same port and host
    name....I haven't tried it myself. My guess is that it's possible. Why don't you just try it and see?
    Good Luck,
    Avi.

  • Help with servlet and JSP

    I am creating a web application that allows users to submit questions and answers to a database. The users can also specify a number of questions and take a randomly generated test from the questions that have been submitted to the database. Currently, I am having trouble figuring out how to generate the test and then grade it. I was thinking I would use a question page that displayed a random question and its answers, allowed the user to answer the question and submit it, and then have the page reload with a new random question from the database. After the user has answered the number of questions they specified, then it would go to a results page with the percent and grade. I'm having trouble figuring out a servlet for the test generation. Any help would be much appreciated.
    Thanks, Mike
    [email protected]

    Please provide more information on exactly what the problem you are having is.
    For example: The following sentence you provide doesn't really say what the problem is:
    " I'm having trouble figuring out a servlet for the test generation."

  • Help With Servlet & SQL

    I'm working on a project for my Java class and I'm running into trouble with the JDBC section. My project is laid out as follows:
    This project consists of a HTML page, a servlet, and a database. I have already wrote up the code for the interaction between the login page and the servlet, however, I cannot figure out how to use java to interact with a Microsoft Access database.
    I'm trying to call to a method (which has the coding for JDBC & SQL) by calling to it through the doPost method. The program refuses to go to that method. I'm not sure if it's a syntax error or if it's not even allowed in Java. I think I've narrowed the problem down to this line:
    String user = getUser(username, password);
    getUser is the method I was refering to in the previous paragraph. When getUser as it's own class, without dealing with paramters, it works fine. When I calling it with parameters, it doesn't seem to work. It will not even return a string when I call it. If you need the getUser code, I can provide it.
    I hope I am being clear, if not please let me know. Thanks in advance for any help you can provide. It is much appreciated.

    I'm trying to call to a method (which has the coding
    for JDBC & SQL) by calling to it through the doPost
    method. The program refuses to go to that method. I'm
    not sure if it's a syntax error or if it's not even
    allowed in Java. I think I've narrowed the problem
    down to this line:
    String user = getUser(username, password);
    getUser is the method I was refering to in the
    previous paragraph. When getUser as it's own class,
    without dealing with paramters, it works fine. When I
    calling it with parameters, it doesn't seem to work.This the part that is a little confusing.
    You should always be able to call a method. The method may not return anything, but if the method exists and you supply the correct parameters, you can call it, or as you put it, "go to it". I.e.,
    public void doGet( HttpServletRequest request,
                       HttpServletResponse response ) {
       ... // some code that defines the output stream as "out"
       out.println( "The user's name was " + getUser( username, password ) );
    }Would work. You've "gone to" the method.
    That is a completely seperate problem from the getUser() method not working when you provide parameters. I suspect getUser() isn't working because you either provide the incorrect parameters, or you're expecting the wrong return value.
    This is one of those examples when being able to see your code would really help.
    However, I can make a guess... You've defined the function as:
    String getUser( username, password ).
    I would guess getUser() takes the username expressed as a string, the password expressed as a string, and returns what... the username as a string? In which case, why do you need getUser()?
    Another possibility is that Microsoft Access isn't really a multi-user application, I don't think it requires you to log in and present your credentials (the password). That may explain why it works when you call getUser() without any parameters.

  • Need help with servlets!!!

    Hi, I'm a beginner in Oracle and Servlets. So far I was able to make a servlet which could run a query to an existing table of an oracle database and return this data in an HTML form generated by that same servlet.
    I need some help on making a servlet that can accept user input and make an insert into that same existing table.
    null

    I suggest you break up the problem into manageable sub projects and solve each one in isolation. First, create a 'hello world' servlet. Search google for examples. Here is one problem with your code: if WelcomeServlet3 is in a package called 'myServlets, then you would use something like this: <servlet-class>myServlets.WelcomeServlet3<;/servlet-class> in the web.xml file.
    Next, is your database connection: I suggest you create a database connection in a class with a 'public static void main(String[] args) method to call it. Have the configuration data within the class. Dont get it from an xml file. This way, you can run it stand-alone by right clicking on the class and choosing 'run as application' and therefore ensure it works.
    Next go to the tomcat home page and read up on how to configure a database in tomcat by putting the configuration data in an xml file. Make sure you're reading the about the version of tomcat you're using. For all versions of tomcat, its something like this: If your web application is called 'myWebProject', then there should be an configuration xml file called 'myWebProject.xml' that goes under one of the tomcat sub folders. You use JNI to get the configuration data out of that xml file to configure the database. There is no database configuration data in the web.xml file.

  • Help with Servlet Addressing

    I'll never, ever, as long as I live ever figure out where to put JSP stuff in my directories.
    in my tomcat I have an examples directory with a helloworld servlet...
    C:\jakarta-tomcat-4.1.12\webapps\examples\WEB-INF\classes\HelloWorldExample.class
    that I can access from my browser at URL...
    http://localhost:8080/examples/servlet/HelloWorldExample
    I've created a new directory on my tomcat to hold the website I want to develop...
    C:\jakarta-tomcat-4.1.12\webapps\dumfries
    In it I have copied the HelloWorldExample.class file so that it sits at address...
    C:\jakarta-tomcat-4.1.12\webapps\dumfries\WEB-INF\classes\HelloWorldExample.class
    But, after stopping/restarting the server I go to url
    http://localhost:8080/dumfries/servlet/HelloWorldExample
    I get "The requested resource (/dumfries/servlet/HelloWorldExample) is not available."
    The paths to the HelloWorldExample.class files in "examples" and "dumfries" are identical below the parent directory...
    C:\jakarta-tomcat-4.1.12\webapps\examples\WEB-INF\classes\HelloWorldExample.class
    C:\jakarta-tomcat-4.1.12\webapps\dumfries\WEB-INF\classes\HelloWorldExample.class
    And the url's follow the same address structure...
    http://localhost:8080/examples/servlet/HelloWorldExample
    http://localhost:8080/dumfries/servlet/HelloWorldExample
    but one works and the other doesn't!!
    WHY WHY WHY WHY (sound of hair ripping out) WHY WHY WHY

    Don't pull your hair out! The stress will make it fall out by itself!
    Besides, your answer is at your question in the other forum:
    http://forum.java.sun.com/thread.jsp?forum=33&thread=357756
    Also, check out some working code:
    http://forum.java.sun.com/thread.jsp?forum=45&thread=357607

  • Help with Servlet and Unix Commands

    Hello,
    I want to write a Java Servlet that runs some Unix commands on the system..
    Any guidelines? A really small and simple java servlet example that runs "ls -la" for example and outputs the results would be great...
    Any help would be greatly appreciated :)
    Thanks in advance

    You'll want to use Runtime.exec() to run Unix commands.
    Why can't you just get this out of java.io.File.listFiles()? What's ls really doing for you here?
    If you insist on using Runtime.exec(), you'll want to read this:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    MOD

  • Beginner needing help with servlet setup

    im trying to setup a simple servlet but it seems that my html page will not invoke the java servlet. perhaps it is due to the location of the servlet class, is there a special directory to store the servlet in? or will storing it in the same dir as the html page suffice? Im using j2ee application server here is the html code im using:
    <FORM ACTION="UploadTest" ENCTYPE="multipart/form-data" METHOD=POST>
    What is your Name? <INPUT TYPE=TEXT NAME=submitter> <BR>
    Which file would you like to upload? <INPUT TYPE=FILE NAME=file> <BR>
    <INPUT TYPE=SUBMIT>
    </FORM>
    the directory im working in is:
    C:\Sun\AppServer\domains\domain1\docroot\upload
    which contains the html and the .java servlet
    the servlet is named UploadTest.java
    any advice would be appreciated

    ur class file should be in
    WEB-INF\classes folder
    then u should map this class with the urlpattern in the web.xml file
    u can invoke the servlet only with url pattern ur giving in the web.xml
    i think u get me
    regards
    shanu

  • Please help with servlet and database!!

    Hello,
    i first created a servlet that generated an html page and printed out the parameters of a user's username when they logged in. example, "Welcome user" and it worked fine...
    i inserted a database into my site that validates the username and password, and ever since i did that in dreamweaver, when a user logs in sucessfully, it returns the servlet page like its supposed to, only that it says "Welcome null" instead of "Welcome John." pretty strange, huh!? can anyone please help? thanks!

    Check whether the username textfield name has changed or not. Also print the code over here so that we can check the code.

  • Help with Servlet - JSP Newbie

    I'm trying to teach myself jsp. I've created a couple of classes to do my data I/O. I have a form to collect user data and the page the form posts to should write the data to a text file. When I run the form and form handler the data is presented back to the user and everything looks fine... no errors or anything. However, the text file I'm trying to create/append does not get modified. Any suggestions would be greatly appreciated as I can't move on with what I want to do until I figure this out.
    Thanks,
    Steven Lee / EMC
    [email protected]
    I'm running Apache 2.0.52/Tomcat 5.5 on Win 2000. Here's my directory structure:
    C:\Apache\Tomcat 5.5.\webapps\ROOT
    /ROOT
    index.jsp
    OptIn.jsp
    show_email_entry
    /admin
    /WEB-INF -->web.xml
    /classes
    /business -->User.class
    /data -->UserIO.class
    /lib
    ***UserIO.class:***
    package data;
    import java.io.*;
    import business.User;
    public class UserIO{
    public synchronized static void addRecord(User user, String filename)
              throws IOException{
                   PrintWriter out = new PrintWriter(
                        new FileWriter(filename, true));
                   out.println(user.getEmailAddress() + "|"
                        + user.getFirstName() + "|"
                        + user.getLastName() );
                   out.close();
    ***User.class***
    package business;
    public class User {
         private String firstName;
         private String lastName;
         private String emailAddress;
         public User() {}
         public User(String first, String last, String email) {
         firstName = first;
         lastName = last;
         emailAddress = email;
         public void setFirstName(String f) {
              firstName = f;
         public String getFirstName() { return firstName; }
         public void setLirstName(String l) {
              lastName = l;
         public String getLastName() { return lastName; }
         public void setEmailAddress(String e) {
              emailAddress = e;
         public String getEmailAddress() { return emailAddress; }
    ***OptIn.jsp***
    <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>
    <body>
    <p>Join E- Mail List</p>
    <form action="show_email_entry.jsp" method="get" name="FRMjoinList" id="FRMjoinList">
    <input name="txFN" type="text" id="txFN">
    first name
    <br>
    <input name="txLN" type="text" id="txLN">
    last name <br>
    <input name="txEMAIL" type="text" id="txEMAIL">
    e-mail <br>
    <input type="submit" name="Submit" value="Submit">
    </form>
    <p> </p>
    </body>
    </html>
    ***show_email_entry.jsp***
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>
    <body>
    <%@ page import="business.*, data.*, java.util.Date" %>
    <%
         String firstName = request.getParameter("txFN");
         String lastName = request.getParameter("txLN");
         String emailAddress = request.getParameter("txEMAIL");
         User user = new User(firstName, lastName, emailAddress);
         UserIO.addRecord(user, "UserEmail.txt");
    %>
    <p>Today's Date is <%=new Date() %></p>
    <H2>Thanks for joining our list</H2>
    <p>Here's your information:</p>
    <table width="300" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="92">First Name </td>
    <td width="208"><%=user.getFirstName() %></td>
    </tr>
    <tr>
    <td>Last Name </td>
    <td><%=user.getLastName() %></td>
    </tr>
    <tr>
    <td>E-Mail</td>
    <td><%=user.getEmailAddress() %></td>
    </tr>
    </table>
    <p>Click here to enter another address.</p>
    <form name="form1" method="post" action="optIn.jsp">
    <input type="submit" value="Return">
    </form>
    <p> </p>
    </body>
    </html>

    I just realized that the file is given as just a filename. No path.
    Are you SURE the file isn't being created, just somewhere you don't expect?
    Try putting a full path in there instead of just a filename.

  • Help with Servlet/HTTP/Database

    Hi,
    I am an 18 year old student, about to enter university and very new to JAVA. Would anyone be kind enough to put down the script for a simple servlet/HTTP login page that is connected to a database and explain some of the key features of it for me please.
    I am currently working through a JAVA How to Program book by Deitel & Deitel and they do not seem to have a good example of it and the ones I found on Google are not very well explained.
    Thank you very much in advance.

    Note: This thread was originally posted in the [Java Programming|http://forums.sun.com/forum.jspa?forumID=31] forum, but moved to this forum for closer topic alignment.

  • Help With Servlet+JDBC Example?

    hi there
    i've made my first jsp page
    that contain two textfields name&description
    and i want that when the user presses the add button
    the information is sent to the servlet and the servlet add the information in the database
    how that can be done in the servlet?
    thank you

    You can extends the httpservlet, then implements the method of the doGet,and you can do what you want to do&#12290;
    it is easy&#65292; u had better find some book to read&#12290;

Maybe you are looking for