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.

Similar Messages

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

  • 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

    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).

  • I need help with the https class please.

    Hello, i need add an authentication field in my GET request using HTTPS to authenticate users. I put the authentication field using the setRequestProperty method, but it doesn't appear when i print all properties using the getRequestProperties method. I wrote the following code:
    try{
    URL url = new URL ("https://my_url..");
    URLConnection conexion;
    conexion = url.openConnection();
    conexion.setRequestProperty("Authorization",my_urlEncoder_string);
    conexion.setRequestProperty("Host",my_loginServer);
    HttpsURLConnection httpsConexion = (HttpsURLConnection) conexion;
    httpsConexion.setRequestMethod("GET");
    System.out.println("All properties\r\n: " + httpsConexion.getRequestProperties());
    }catch ....
    when i run the program it show the following text:
    All properties: {Host=[my_loginServer]}
    Only the Host field is added to my HttpsURLConnection. The authentication field doesnt appear in standar output. How can i add to my HttpsURLConnection an Authentication field?
    thanks

    I have moved this to the main Dreamweaver forum, as the other forum is intended to deal with the Getting Started video tutorial.
    The best way to get help with layout problems is to upload the files to a website and post the URL in the forum. Someone can then look at the code, and identify the problem. Judging from your description, it sounds as though the Document window is narrow, which would result in the final menu tab dropping down to the next row. Try turning on Live view or previewing the page in a browser. Design view gives only an approximate idea of the final layout. Live view renders the page as it should look in a browser.

  • 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 building a database portlet (reference_path) issues

    I'm attempting to create a Provider Portlet based on the Database Provider example. The goal of the portlet is to
    dynamically display a Portal Report based upon a session storage variable. The session storage variable is set in another portlet on the same page. My portlet is named DYNAMIC_RPT.
    I'm able to display the report from within my database portlet by calling the report's .show procedure.
    But, my problem is this: The reference_path is generated for my database portlet, for example 131_DYNAMIC_RPT_123123, so when I click the NEXT button on the report, the page is refreshed but the report is still on page 1.
    I think the problem is that my portlet needs to internally determine what the reference_path SHOULD BE for the report I'm trying to display, and use it in the associated provider API's.
    If I could call the API which is generating the reference_path I could then pass an appropriate reference_path. I would need to be able to dynamically regenerate the reference_path when ever the session variable changes. Is this possible ?
    Also, when I'm building the p_arg_names, and p_arg_values whould I ONLY extract the argument(parms) which are associated with the p_reference_path of the portlet report currenttly being displayed ?
    Also is there a session storage variable which contains the current PAGE ID and TAB ID. I'm extracting it form the PAGE_URL but it's very messy code.
    Thanks in advance for your help !!

    Hi,
    you can do what you want with LiveCycle, and it might help you to look at this reference as it shows how to work with data ( it does depend how your data is stored)
    http://help.adobe.com/en_US/livecycle/9.0/designerHelp/index.htm?content=000006.htmlhttp://help.adobe.com/en_US/livecycle/9.0/designerHelp/index.htm?content=000006.html
    If you data does not change very often then I would recommend just using an XML file to store the data and then use thebinding ability with possible some JavaScript to create the solution you would like.
    Hope this helps
    Malcolm

  • 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.

  • Help with creating a database instance and populating it

    the project given to me is to create a database and populate it in berkeley DB. use that as the backend to the Oracle Business Intelligence tool and run some tests.
    with other databases like oracle, sybase and teradata, there were user interfaces both GUI and CLI to create a database. they provides sql interfaces for DDL/DML execution to create objects and populate them. basically these utilities helped me do my project successfully. but in berkeley DB i find very minimal utilities and they dont correspond to those provided by other databases.
    is there an interface in berkeley db for sql execution
    in general how do i create database and populate data in berkeley db
    thanks
    [email protected]

    Hi Prasanna,
    is there an interface in berkeley db for sql executionNo, Berkeley DB does not provide an SQL interface. It is a library that can be used to store and retrieve key/data pairs in a database. The Berkeley DB reference guide is a good place to look if you want to get an overview of Berkeley DB functionality:
    http://www.oracle.com/technology/documentation/berkeley-db/db/ref/toc.html
    in general how do i create database and populate data in Berkeley db You generally need to write code to do that. There are a number of programming language bindings provided for Berkeley DB, including a Perl binding. So you can write your testing code in the Perl scripting language if that suits you.
    If you intend to measure performance I would recommend using the C or C++ APIs to build your application. The best way to become familiar with using Berkeley DB is with the Getting started guides found here:
    http://www.oracle.com/technology/documentation/berkeley-db/db/index.html
    Or by familiarizing yourself with the example applications that are shipped with the source distribution.
    Regards,
    Alex

  • 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 structuring SQL databases for multiple photo galleries..help!?!

    Hello all,
    As a new PHP/SQL developer I have found great technical assistance from both this forum and from David Powers and his wonderful books. I am at a crucial point in my web development and although I believe I know which direction I need to go, I am still uncertain and so I appeal to you all for your help, especially David Powers.
    The website I am building is one which will house many photo galleries. I was able to successfully modify the code provided in David Powers’ book ‘php Solutions’ so that I got the photo galleries constructed and working in the manner I desired.
    That being said, a person browsing my website will be presented with a link to see the photo galleries. There will be five (5) categories in which the photos will be separated, all based on specific styles. Now that I have the galleries working, I need to know how to structure things so that I can create a page, like a TOC (table o’ contents) that shows all photo galleries by displaying a thumbnail image or two along with the description. Perhaps I’ll limit the TOC page to only show the latest 25 galleries, arranged with the most current always on top.
    The way I have my galleries set up, I have a separate database for each one, containing the photo filenames and other relevant data. To build my TOC structure, should I have an overall database that contains each gallery database filename along with category? This is where I have no idea what I’m doing so if my question sounds vague, please understand I have no other idea how to ask.
    The site will grow to the point of having hundreds, if not thousands of photo galleries. I simply want to know how to (organize them) or otherwise allow me to build a method to display them in a TOC page or pages.
    I know this is a bit dodgy, but with some info and questions back from you, I feel confident that I should be able to get my point across.
    Lastly, I am still developing this site locally, so I have no links to provide (though I feel that shouldn’t be necessary right now).
    Many sincere thanks to you all in advance,
    wordman

    bregent,
    I'm chewing this over in my head, reading up on DB's in 'phpSolutions' and I think that things are slowly materializing.
    Here is the structure of the website that I have planned:
    MAIN PAGE
    User is presented with a link on the main page to select photo galleries (other links are also present). Clicking the link takes them to the Category Page.
    CATEGORY PAGE
    On this page, the User will then have 5 choices based on categories (photo style). CLicking any of these 5 links will take them to respective TOC pages.
    TOC PAGE
    On this page, the user is greeted with a vertical list of galleries or photosets; one to three thumbs on the left, a small block of descriptive text on the right (ideally containing date/time info to show how recent the gallery is). Newest galleries appear at the top. Eventually, when there are tens or hundreds of galleries in any given catrgory, I'll need to adopt a method for breaking up the qualntity in groups (we can pick 20 for example) that can be scrolled through using a small navbar. This will keep the TOC Pages from getting endlessly long and avoid endless scrolling. User selects a gallery on this page to view.
    THUMBNAIL PAGE
    On choosing a gallery, a thumbnail page is generated (I have this working already)
    IMAGE PAGE
    On selecting any thumbnail in the grid, the user is taken to the full-sized photo with a navbar and photo counter at the top. Navlinks allow forward and back, a link to the first image, a link to the last image and one link back to the thumbnail page. (I have this working already).
    I provide this info in an effort to help understand the basic structure of my site. The description above is as close to a step-by-step illustration as possible.
    Thank you!
    Sincerely,
    wordman

  • Need Help with my frist database

    I am developing a Java application locally with a very simple database.
    Where do I begin when I want to make a database? I know SQL but never done a connection to database.
    I can do my tables with a database tool program (does Sun have such a program for design of database?)
    When I am trying different database tools, they want me to connect to the db-server? What does it mean? How do I choose a db-server (this is not a web application).
    Thank you for some advice to push me in the right direction...
    Kia

    I by myself (the writer of this topic), found a great website with instructions in details for newbie like me. I am recommending it to everyone who is doing its first database:
    http://www.developer.com/java/data/article.php/3417381
    Questions I made before are all answered here, as:
    Getting things up and running
    As a minimum, getting up and running with MySQL and JDBC involves at least the following steps:
    Download and install the appropriate release of the MySQL database server software (several different releases are available).
    Download and install the MySQL Connector/J -- for connecting to a MySQL database server from Java.
    Download and install the documentation for the MySQL database server.
    Download and install the documentation for the Connector, which is a separate documentation package from the database server documentation.
    Write and test one or more JDBC programs that will act as a database administrator, creating one or more users and possibly one or more databases on the database server. (I will show you three different ways to accomplish this.)
    Write and test a JDBC program that will log in as a user and manipulate data stored in one of those databases.
    Nice yeee... This was what I needed...
    Message was edited by:
    Kia70
    Message was edited by:
    Kia70

Maybe you are looking for

  • Cannot import or view iPhone photos in iPhoto.

    I am trying to import photos from my iPhone into iPhoto. My phone shows up as a device in iPhoto, but none of the image previews load and the import buttons are greyed out. With Image Capture I have the same problem, the device is recognized but noth

  • Drag and dropping database objects in Jdev

    I evaluated Visual Cafe and deciding wheather to go with VC or JDev. One of the cool things I noticed in VC is that one can drag and drop database objects in the form using DBNavigator. I haven't seen anything similar in JDev 3.1. Does this or someth

  • Not able to connect to any phone via bluetooth

    Hi I have tried with sevral phones but not able to pair with any phone except apple itself via bluetooth. After verification of passcode, it shows processing for sometime and then message appears "not able to connect" or so! Please suggest.

  • What Features are provided by Software Packs 8.6.1, 2 and 3

    We have a UC560 customer with Software Pack 8.2 installed and they are wondering what, if any advantages there are if they upgrade to Software Pack 8.6.2. I thought there was a good feature Matrix published at one time, but I have been unable to find

  • Right SAPup version for upgrade from ECC 5.0 to ECC 6.0

    Dear Expert! I am upgrading from ECC 5.0 to ECC 6.0 , but i have a erro, with SAPup tool, I don't know to select right SAPup version, please show me about that, thank you very much! Tru Hang