Updating a servlet

Here is a scenario:
A user enters a query and submits it to servlet. The servlet prints "thanks for the visit, ur query is being dealt with". At the same time the servlet is accessing a database and searching for user's query. Then the servlet updates itself with the information from the database.
My real question is that how can a servlet update itself. For example, how would it know that it has retrieved data from the database.
Would I need to use respond.setHeader(....) method.
Thanks
Qasim

in your code to get information from database you would have something like
while( resultset.next()) {
//keep reading
once all the information is taken from database and you are out of while loop,at that point you can direct the out put to your page exactly the way u sent thank and it will reflect the info from db in the same page where u had "thank u " for user.
I hope this answers ur question
Khalid Ali

Similar Messages

  • Updating through servlet fails!

    Hello everyone!
    I have a servlet which updates the emps table in oracle database.
    --the code
    package oz;
    import java.sql.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    public class UpdateScottEmployees extends HttpServlet{
    public void doGet(HttpServletRequest request,HttpServletResponse response)
    throws ServletException,IOException{
    doPost(request,response);
    }//doPGet
    public void doPost(HttpServletRequest request,HttpServletResponse response)
    throws ServletException,IOException{
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    Connection cn = null;
    Statement stm = null;
    try{
    //Load the driver
    Driver drv = (Driver) Class.forName("JData2_0.sql.$Driver").newInstance();
    //Oracle Connection
    cn = DriverManager.getConnection("jdbc:JDataConnect://zaf/scott_emp:scott:tiger");
    stm = cn.createStatement();
    String upd = "INSERT INTO emp(empno,ename,job,mgr,hiredate,sal,comm,deptno)" +
    "VALUES(" +
    request.getParameter("theempno") + "," +
    "\"" + request.getParameter("theename") + "\"," +
    "\"" + request.getParameter("thejob") + "\"," +
    request.getParameter("themgr") + "," +
    "\"" + request.getParameter("thedate") + "\"," +
    request.getParameter("thesal") + "," +
    request.getParameter("thecomm") + "," +
    request.getParameter("thedeptno") + ")";
    stm.executeUpdate(upd);
    cn.close();
    stm.close();
    out.println("<P>Update done!</P>");
    }catch(Exception e){
    out.println(e.toString());
    }//doPost
    }// UpdateScottEmployees
    and the html file
    <HTML><HEAD>
    <TITLE></TITLE>
    </HEAD>
    <BODY>
    <H3 align="center">Update form</H3>
    <BR>
    <FORM ACTION="../../servlet/oz.UpdateScottEmployees" METHOD="POST">
    Employee number:<INPUT TYPE="text" NAME="theempno"><BR>
    Employee name:<INPUT TYPE="text" NAME="thename"><BR>
    Employee job:<INPUT TYPE="text" NAME="thejob"><BR>
    Employee manager:<INPUT TYPE="text" NAME="themgr"><BR>
    Employee hiredate:<INPUT TYPE="text" NAME="thedate"><BR>
    Employee sal:<INPUT TYPE="text" NAME="thesal"><BR>
    Employee commission:<INPUT TYPE="text" NAME="thecomm"><BR>
    Employee Department no:<INPUT TYPE="text" NAME="thedeptno"><BR>
    <INPUT TYPE="SUBMIT" VALUE="update">
    </FORM>
    </BODY>
    </HTML>
    When i click the submit button i get the following message:
    java.lang.ClassNotFoundException: JData2_0.sql.$Driver
    However i have tried the driver class and it seems to work. What's the problem?
    Any help would be appreciated!
    Thanks in advance!

    Hello again!
    I think my classpath is set correctly because a simple java program placed in the same directory succeeds with the connection.Do you think the problem is placing the driver class inside doGet() or doPost() ?

  • Db updation from servlet

    hi ,
    I am new to sevlets and trying to update an access db through a servlet using the
    code given below.
    String strUpdate ="UPDATE TABLE ProposalTrackingSystem "+
                        "SET Responsibilities = '"+strRespo+"'"+
                        "WHERE ProposalNumber = "+strPN ;
    where strRespo and strPN are String variables.
    It gives the following error :
    javawebserver: The Update Query : UPDATE TABLE ProposalTrackingSystem SET Respon
    sibilities = 'Full .. No Less'WHERE ProposalNumber = 1
    javawebserver: Exception thrown :[Microsoft][ODBC Microsoft Access Driver] Synta
    x error in UPDATE statement.
    pleeeeezzz help...
    thanks in advance

    well, thanxxxx sudha.. but before i got ur reply i used this :
    String strUpdate ="UPDATE ProposalTrackingSystem SET Responsibilities='"+strRespo+"' WHERE ProposalNumber="+strPN;
    and it runs now
    the blankspace wala funda .. am aware of.. was just a typing error..
    thanx again for ur prompt reply
    kuttudi

  • Why I need to restart my my server to update my servlet in WL5.1

              Hai
              We have servlets and ejbs in our acchitecture and using weblogic5.1. For EJBs
              weblogic have given hot deploy. But for every change of servlets currently we
              are stopping the server and replacing the servlet class and starting the server.
              Since we getting drastic changes we need to update or deploy servlet in the existing
              running server. Is there any thing is available for servlets or normal classes
              to update in the server. Thanks In Advance
              Kiran N
              

              Hi,
              What is the service pack you are using?
              You should be able to dynamically load the servlet classes.
              Please make sure that you put your servlet classes in servlet classpath:
              weblogic.httpd.servlet.classpath=....
              For every reload check secs server will check for any changes in the classes
              and loads if they are changed.
              Also make sure that you do not have the same class in the system classpath.
              --Vijay
              "Kir" <[email protected]> wrote:
              >
              >Hai
              >
              >We have servlets and ejbs in our acchitecture and using weblogic5.1.
              >For EJBs
              >weblogic have given hot deploy. But for every change of servlets currently
              >we
              >are stopping the server and replacing the servlet class and starting
              >the server.
              >Since we getting drastic changes we need to update or deploy servlet
              >in the existing
              >running server. Is there any thing is available for servlets or normal
              >classes
              >to update in the server. Thanks In Advance
              >
              >
              >Kiran N
              

  • Update a servlet automatically

    Hello,
    I try to make a servlet.
    but each time i change my .java file, i need to stop and start again TOMCAT for viewing the change on my servlet.
    Does he have a way for each time i change my .java file TOMCAT take the update automatically?
    i use TOMCAT 5 with Apache on a Gentoo linux.
    thanks for helping me!

    If you have defined your context definition outside server.xml (should be in path as below),
    <TOMCAT_INSTALL/conf/<enginename>/<hostname>/<your_context_name.xml>An example application called webtest running on localhost and with the default engine name as Catalina would have this path.....
    <TOMCAT_INSTALL/conf/catalina/localhost/webtest.xmlall you have to do is add an attribute reloadable = "true" to your context definition in the xml above.
    <?xml version='1.0' encoding='utf-8'?>
    <Context docBase="D:/ram/technical/webtest" path="/webtest"
    reloadable="true" workDir="D:\ram\technical\webtest\work">
    <!-- define context resources here -->
    </Context>Cheers,
    ram.

  • Why is this table trigger not firing when insert/update from servlet?

    Hi!
    I have this servlet that parses XML and stores values into Oracle tables. I have created a table trigger so that when one table is updated, a trigger is fired and the current system date is store in another table's field.
    I have tested the trigger in Toad and it works, that is, if I update the table that the trigger is set to, the SYSDATE is stored as intended.
    Here is the trigger's code:
    DECLARE
    tmpVar NUMBER;
    NAME: transaction_time
    PURPOSE:
    REVISIONS:
    Ver Date Author Description
    1.0 9/14/2007 1. Created this trigger.
    NOTES:
    Automatically available Auto Replace Keywords:
    Object Name: transaction_time
    Sysdate: 9/14/2007
    Date and Time: 9/14/2007, 8:00:42 AM, and 9/14/2007 8:00:42 AM
    Username: (set in TOAD Options, Proc Templates)
    Table Name: MS_RESLIMITS (set in the "New PL/SQL Object" dialog)
    Trigger Options: (set in the "New PL/SQL Object" dialog)
    BEGIN
    tmpVar := 0;
    UPDATE MS_Misc SET mi_lastrun = SYSDATE;
    EXCEPTION
    WHEN OTHERS THEN
    -- Consider logging the error and then re-raise
    RAISE;
    END transaction_time;
    Now, when the table is updated by the servlet, the trigger does not fire. And here is the code from the servlet:
    --- <start of code> ---
    boolean recordExists =
    this.isRecordPresent("MS_ResLimits", "rl_compcode",
    compCode, url);
    Connection rlConn = null;
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    rlConn = DriverManager.getConnection(url, dbUser,
    dbPwd);
    Statement stmt = rlConn.createStatement();
    PreparedStatement xmlUpdate = null;
    if (recordExists) {
    xmlUpdate =
    rlConn.prepareStatement("UPDATE MS_ResLimits SET rl_compcode = ?, rl_maxreslimit= ? WHERE rl_compcode =?");
    xmlUpdate.setString(1, compCode);
    xmlUpdate.setString(2, maximumReservationDate);
    xmlUpdate.setString(3, compCode);
    } else {
    xmlUpdate =
    rlConn.prepareStatement("INSERT INTO MS_ResLimits VALUES(?,?)");
    xmlUpdate.setString(1, compCode);
    xmlUpdate.setString(2, maximumReservationDate);
    } //end-if-else
    int n = xmlUpdate.executeUpdate();
    rlConn.commit();
    } catch (Exception ex) {
    out.println(ex.toString() +
    "-> error inserting Max Reservation Date<br>");
    } finally {
    if (rlConn != null) {
    rlConn.close();
    } //end-try-catch-finally
    --- <end of code> ---
    What causes the trigger to fire? the commit? My understanding is that executeUpdates are in autocommit mode by default, or am I mistaken? Do I have to programmatically send something to the DB so that the trigger fires?
    BTW, I'm using JDeveloper 10.1.3.3.0. The project is being compiled with Java 1.5.0_06. The servlet is running in OCJ4 standalone. DB is 10g (don't know the release version).
    ...and, for some reason this message is not keeping format from my edit window to the post...
    Thx!
    Message was edited by:
    delphosbean
    Message was edited by:
    delphosbean
    Message was edited by:
    delphosbean

    You are supposed to be able to preserve you formatting using the <pre></pre> tags but I can't get this to work either<br>
    <br>
    Patrick.

  • Synchronizing DB updating in servlet

    hi,
    i'd like to the know what code I should synchronize when updating my database. I currently just have the lock as follows in a servlet:
    synchronized(this){
                statement.executeUpdate();
           }but i'm wondering if this is enough and if i should synchronize my
    statement.setString(x, x) calls?
    thanks

    Only one object at a time may access the synchronized block, so that will work fine.

  • Status updates while servlet is running...

    I have a servlet that launches a dozen different thread to process a bunch of network information. Now, these all work fine and I have a please wait page while they run (about 45 sec) but the users are getting ansy during this time and would like some feedback while the process are running.
    I thought, no problem, I'll send a message back to the user when each process thread finishes. No such luck, I get one of two results with my attempt at coding this. First, the messages do not show until the main controlling servlet is finished and they are just thrown in at the top of the results page. Or, second, the messages all come up as they are suppose to but then the results page never displays.
    What am I doing wrong? Thanks!
    Ross

    I set up a <DIV> tags on the request page that has the Please wait HTML in it. Then during the submit, I call some JavaScript that hides the first DIV section and displays the second. Bceause the DOM is not standard across browsers, hence why I want to have the servlet do this rather than my current method. I needed to write this JavaScript function so this would work in most browsers:
    function PostandWait() {
        if(document.getElementById) {
            document.getElementById('main').style.display='none';
            document.getElementById('main').style.visibility='hidden';
            document.getElementById('banner').style.visibility='hidden';
            document.getElementById('wait').style.display='block';
        else if(document.layers) {
            document.layers["main"].visibility="hidden";
            document.layers["wait"].visibility="show";
        else if(document.all) {
            document.all["main"].style.visibility="hidden";
            document.all["wait"].style.visibility="visible";
        else {
        document.jobform.submit();
    }//PostandWait

  • Question about multiple servlet comms

    all,
    Ok here is the setup:
    Let�s say I have 3 servlets (A, B, C)
    A is started and then responsible for polling a database to check for updates since last poll until it is destroyed on server shutdown
    B is an intermediary servlet
    C is responsible for pushing data to the client�s that have subscribed
    The problem is this:
    A is invoked and begins periodically checking a DB for updated data. Upon finding updated data it should forward the data to B. This does some checking and then in turn forwards the updated data to C. C then formats the data and pushes it to the client�s browser where it is displayed as SVG.
    I am thinking B->C could simply be resolved through the use of a request dispatcher.
    However the problem lies in the communication of A->B.
    Since servlet A should frequently (once a sec) poll and check the database contents to see if it has been updated I thought an easy way to do this would be to have the servlet make its check; if nothing has changed redirect the response back to itself. If there has been a change, update servlet B with that change. The problem is how can one send the update to servlet B without halting servlet A�s cycle?
    If I open a httpURL connection to B then A will wait for B to pass a response back, but B wants to forward the request, via request dispatcher to C after some processing. Therefore A will hang as no response from B will be written.
    If I have A use a request dispatcher to forward the data to B I am unable to redirect the response back to A and thus have it continuously checking.
    Unfortunately it is unlikely I can make any changes to the architecture. Any ideas?
    Kind regards

    Sorry I can't help but I am interested in a similar problem.
    Anyone out there?

  • Deployment: servlet version differences?

    Oracle 8.1.7 (pc, NT4)
    iFS 1.1.9 (on the same oracle root)
    JDeveloper 3.2 (on another pc)
    I've got ever so close to getting my app working on Oracle 8.1.7 with Apache. I'm getting the following error when i try to add new or edit a record:
    java.lang.NoSuchMethodError: javax.servlet.ServletRequest: method setAttribute(Ljava/lang/String;Ljava/lang/Object;)V not found
    A search in past topics leads me to believe i'm running a version of Servlet specification that does not support 'setAttribute'. When I do a search for servlet.jar i get the following
    On the oracle box:
    /orant/lib/servlet.jar...45k
    /orant/jis/lib/servlet.jar...45k
    /orant/ifs1.1/jws/lib/servlet.jar...25k
    On the jdeveloper box:
    /jdeveloper/lib/servlet.jar...40k
    The installation of ifs uses /orant/jis/lib/servlet.jar.
    So what's the story? Do I need to upgrade something here or is it a matter of copying a few more files over from the jdeveloper installation.
    If I need to update my servlet specification please point me in the right direction.
    soooo close, thanks, DC

    if you're deploying your jdev 3.2.2 servlet (which uses servlet api 2.1 and 2.2) to the the apache jserv component which only supports servlet api 2.0 -- you will have problems.
    you need to deploy these servlets to the oracle servlet engine (ose) component found in the oracle 8i jvm component of the ias 9i or rdbms817 products.

  • Problem with Tomcat 4.1.24 when Using Servlets

    hi
    I am using tomcat webserver.. when I am making modifications in the servlets, everytime i am shutting down the tomcat server bcoz the servlet is not getting updated in the webserver.. can any one tell me the solution to dynamically update the servlets without shutting down the tomcat webserver each time i modify the servlets..
    sanjay

    Use the Tomcat manager to install/remove the WAR file during development. That way you don't have to shutdown and startup the server:
    http://kam02622:8080/index.jsp
    Go into the manager app and you'll be able to see all the applications that are running.
    Better yet, use the Catalina Ant tasks if you're using Ant as your build tool. I recommend this. - MOD

  • Session expires when servlets are reloaded

    Hi
    I'm using Sun Java System Web server 7.0 on Windows 2003 server. When I update my servlets the session expires. I update the .reload filen and the servlets reloads perfect, but my users session expires.
    Is it posible to reload servlets without session expires ? And how do I do that ?
    Regards,
    Stian Martinsen
    Norway
    Edited by: StianNorway on Sep 14, 2007 3:59 AM

    I don't know about Sun's server but with Tomcat, if you are careful to make sure that every object bound to session (directly or indirectly) implements java.io.Serializable, Tomcat will save all your session information to disk when the application restarts so they are all live when it comes back up.
    Read the documentation for your server and see if it has a similar feature.

  • Server servlet help

    we are running oracle IAS 8i which seems to just be Apache with Jserv modules loaded. Now the problem is my co-worker when ever she updates her servlets, she has to restart the apache instance. Instead of creating a new daemon for development purposes, surely there is a way to automatically load the new servlets, is there?

    I think there is an element in conf that has an attribute called reloadable you need to set it to true
    For example...
    <Context path="/examples" docBase="webapps/examples" crossContext="false" debug="0" reloadable="true" > </Context>
    This way, the server will automaticaly reload servlet classes that changed.

  • [svn:bz-trunk] 23144: Update spring flex core in BlazeDS trunk to buddy jar for version 1.5.1.

    Revision: 23144
    Revision: 23144
    Author:   [email protected]
    Date:     2011-10-27 09:12:49 -0700 (Thu, 27 Oct 2011)
    Log Message:
    Update spring flex core in BlazeDS trunk to buddy jar for version 1.5.1.
    Update flex-servlet.xml for qa-regress webapp to use 1.5 namespace for spring flex. Also set disallow-wildcard-suptopics to false which is required by some tests which use wildcard subtopics.
    Modified Paths:
        blazeds/trunk/qa/apps/qa-regress/WEB-INF/flex-servlet.xml
    Added Paths:
        blazeds/trunk/lib/spring/spring-flex-core-1.5.1.BUILD-SNAPSHOT.jar
    Removed Paths:
        blazeds/trunk/lib/spring/spring-flex-core-1.5.0.RELEASE.jar

  • Mapping Servlet to Directory

    Is it in any way possible to map a servlet only to a directory, but not to the files of that directory. So I could map a servlet to "/", but not to "/*". As it is now a mapping on "/" and "/*" is exactly the same; both map on the whole webapp.
    If this is not possible yet, is there any RFE which requests this behaviour for future versions of the servlet-specs?

    You can map a request just to a specfic directory:
    <servlet>
    <servlet-name>controller</servlet-name>
    <servlet-class>acme.ControllerServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>controller</servlet-name>
    <url-pattern>/catalog/</url-pattern>
    </servlet-mapping>
    In your web app you can still have a directory /catalog/test.jsp
    A request for /catalog/test.jsp will return that page.
    A request for /catalog or /catalog/ will call the servlet.
    There is a good set of examples in the Servlet Speciffication 2.4 in section SRV.11.2.2.
    Keep in mind welcome files may change your expected behavior. Welcome files have been updated in the latest servlet 2.4 specfication. Welcome files have been updated in servlet 2.4 to allow you to map requests to a set of ordered list (which may include servlets) defined in the web.xml. See SRV.9.10 for more details.

Maybe you are looking for