Servlet doPost being called twice

Hello all,
I have a servlet that is being called twice. The servlet is used to direct the user to the next jsp. I have 4 JSPs that the user steps through to add a record to a database. The 1st JSP lists the records that they have and asks them to add, edit or delete. The servlet gets call to direct them to the next JSP that they enter the data (or update) on. It then calls a verification JSP so the user can verify the information before submitting it. If everything is fine they submit the data. This verification JSP calls the servlet that adds or updates the record in the database. The servlet then directs the user to a confirmation page that tells the user if the submit was successful or not.
Here is how the flow is:
servlet -->menu.jsp -->servlet -->add.jsp -->verification.jsp -->servlet -->confirmation.jsp
Everything is fine until the verification.jsp submits to the servlet. That's where the doPost gets called twice.
I have put System.outs in the servlet code to see how many times the doPost gets called. It gets called once for every JSP except the verification JSP. When the user submits the data, the servlet's doPost gets called twice therefore it tries to add the record twice.
Has anyone had this problem before? How do I fix it?
Any help would be greatly appreciated!!
Tracey

Here is the output of the JSP that when submitted, calls the doPost twice:
<HTML>
<HEAD>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<TITLE>PreaPaid Legal Banner Verification</TITLE>
<script language="javascript">
function new_window(url){
link = window.open(url,"Link","toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width=650,height=450,left=50,top=50");
</script>
</HEAD>
<BODY>
<form name="myForm" action="/webapp/BannerTracker/BannerTrackingServlet" method="post">
<H3><font face="Arial">Banner Tracking Verification</font></H3>
<table BORDER=0 CELLSPACING=0 CELLPADDING=0 COLS=2 WIDTH=500><tr><td>
<font face="Arial" size=2>Below are the choices that you made for your image, size of the image and page to direct people to
when they click on your banner.
<br><br>If this is not what you would like, click the "Back" button to return to the Banner Selection page.
<br><br>You can click on the page link to view a sample of the age you have choosen.
</font></td></tr></table>
<P>
<font face="Arial" size=2>
<input type="hidden" name="cmd" value="doadd">
<input type="hidden" name="banname" value="yahoo">
<input type="hidden" name="banlogin" value="test">
<input type="hidden" name="banid" value="1">
<input type="hidden" name="bangname" value="difference">
<input type="hidden" name="bangsize" value="468x60">
<input type="hidden" name="banpage" value="go/test?:home">
<input type="hidden" name="session" value="PPL2P6LcONLiT45pSszZEb1GJ4HvRc5jQMDNPM8wCJ0rCZesD38oEZ4mC3KvCp8mDp00">
<input type="hidden" name="bangtype" value="gif">
<input type="hidden" name="banurl" value="<A HREF="http://www.prepaidlegal.com/go/test?banid=1&Assoc=test"><img src="http://www.prepaidlegal.com/html/buttonsdifference468x60.gif" border=0></A>">
<br><b>Banner name: </b>yahoo
<br><br><b>Page to be directed: </b>Your PPL Home Page
<br><br><b>Image selected: </b><img src=/html/buttons/difference468x60.gif >
<br><br><b>Copy the URL below to the banner source code.</b>
<br><br><img src="http://www.prepaidlegal.com/html/buttonsdifference468x60.gif " border=0>
</font>
<br><br>
<a><img src="/html/buttons/track_back.gif" border=0 onClick="window.history.back();"></a>
<input type=image src="/html/buttons/track_continue.gif" border=0 onClick="javascript:document.myForm.submit();">
</form>
</BODY>
</HTML>
Here is the doPost code from my servlet:
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
System.out.println("doPost called");
String next = "";
try
Command cmd = lookupCommand(req.getParameter("cmd"));
next = cmd.execute(req);
} catch (CommandException ce) {
req.setAttribute("javax.servlet.jsp.jspException", ce);
next = error;
} catch (SQLException se) {
req.setAttribute("javax.servlet.jsp.jspException", se);
next = error;
HttpSession mysession = req.getSession(true);
String session = String.valueOf(mysession.getAttribute("storedSession"));
if (session.equalsIgnoreCase("null"))
session = req.getParameter("session");
try
checkSession(session);
} catch (IOException ioe) {
System.err.println("Session exception: " + ioe.getMessage() + ".");
next = expire;
} else {
try
checkSession(session);
} catch (IOException ioe) {
System.err.println("Session exception: " + ioe.getMessage() + ".");
next = expire;
if ( session != null )
mysession.setAttribute("storedSession", session);
RequestDispatcher rd;
rd = getServletContext().getRequestDispatcher(jspdir + next);
rd.forward(req, res);
</code>
I hope this helps.
Tracey

Similar Messages

  • Servlet Filters getting called twice

    Hi,
    I am debugging my way through a big project and I am noticing when a http requests comes in that some filters are being called twice.
    I checked the web.xml and nothing funny there and I have checked the respective doFilter() implementations and nothing unusual there.
    Any ideas?
    Thanks.

    Many reasons
    1. Filters are chained - the code in doFilter() upto the call to chain.doFilter() is executed before the request reaches the destined endpoint (servlet/jsp).
    Any code after the call to chain.doFilter() is executed after the endpoint (servlet/jsp) processes the request.
    2. When the response is a redirect, it would cause the browser to send a new request transparently to the end user. This new request would also hit the filter as would be expected.
    3. Filters can be used to intercept internal forwards and/or includes by indicating so in the web.xml. So when such an action happens a part of request processing, filters would be invoked.
    cheers,
    ram.

  • Getter method being called twice

    Hi All,
    I have a h:inputText which updates a h:dataTable as soon as the user types something into it (through the use of Ajax4JSF's a4j:support element). In this way I have something similar to a suggestionbox, but which modifies the table underneath rather than displaying a dropdownlist with possible values. My problem is that for some reason the getter method in the managed request-scoped bean to which the h:dataTable is bound, is being called twice everytime a letter is typed into the h:inputText. The first call seems to happen directly after the bean has been constructed, as the value to which the h:inputText is bound is still empty, and the second call after that, but with the correct value obtained from the h:inputText.
    I searched the forums and found posts detailing similar problems, but I couldn't find an explanation of why it happens or a way to get rid of it. The common consensus seems to be to not have any processing intensive operations in the getter and to just accept that it will be called twice.
    Is there really no way around this?
    Thank you,
    Ristretto

    This is just the default behaviour of the JSF lifecycle. The first call checks if there is a default value or a value which is been set in the previous request. The second call gets the newly set value for display which is been set during the request processing. A way to get rid of the first call might be writing your own lifecycle implementation.

  • Servlet doPost never called from VB client

    Hi,
              Is there any way I can check that the weblogic server (servlet container?) is receiving the request before forwarding it to my servlet?
              Description:
              I'm using MSXML2.XMLHTTP ActiveX object to post an xml string to a servlet from an Excel add-in.
              This is working in all but one case.
              The problem I have is that one client's request is not being posted, i.e. the doPost(..) is not being called on the servlet.
              Here's the VBA:
              Dim Req As New MSXML2.XMLHTTP
              Req.Open bstrMethod:="POST", bstrUrl:=sUploadServlet, varAsync:=True, bstrUser:=uname, bstrPassword:=pword
              Req.Send sXML
              Observations:
              * The post works if I make the call synchronous (i.e. VB waits for the response)
              * The post works if I don't send the xml string
              * There are no errors raised in the VBA above
              The servlet container is Weblogic running on Solaris with java 1.3, the client VB runs in Excel 2000, IE is version 6 SP2.
              Thanks,
                   Antony

    Hi friends,
    It seems I have finally found the answer to calling doPost() of HttpServlet from applet. Espcially for those who were working on jdk1.3 or previous would notice that after moving to a higher jsdk version, their code has suddenly stopped calling the doPost() method in servlet the answer to this is that remember to call the getResponseMessage() And disconnect() method on the HttpURLConnection after closing the outputStream on it.
    This is a sample code to Send the object from applet to servlet in order to invoke doPost() method at the servlet.
    //servletGetUser is a url in the form => http://host:port/contextroot/servletName.
         URL DBSrvlet = new URL(servletGetUser);
         HttpURLConnection SrvletConnection = (HttpURLConnection) DBSrvlet.openConnection();
         SrvletConnection.setDoOutput(true);
         SrvletConnection.setRequestMethod("POST");
         SrvletConnection.setUseCaches(false);      
         SrvletConnection.setDefaultUseCaches(false);
         SrvletConnection.setRequestProperty("Content-type","application/x-www-form-urlencoded");
         ObjectOutputStream outputToServlet = new ObjectOutputStream(SrvletConnection.getOutputStream());
         outputToServlet.writeObject(tAdmin);
    outputToServlet.flush();     
         outputToServlet.close();
         // Remember your doPost() method gets fired actually by these last 2 lines.
    SrvletConnection.getResponseMessage()
         SrvletConnection.disconnect();
    Do let me know if this works,
    Thanks,
    Himanshu B.

  • Servlet doPost not called problem

    Hello, I have searched the topics related the this problem, and I still can not solve the problem, please somebody help.
    I have wrote the simple test servlet and applet to send and receive the data, my sample code are as following:
    On the applet side
    URL url = null;
    HttpURLConnection con = null;
    ObjectOutputStream outputToServlet = null;
    try
    url = new URL(urlString);
    con = (HttpURLConnection)url.openConnection();
    con.setUseCaches(false);
    con.setDefaultUseCaches (false);
    con.setDoInput(true);
    con.setDoOutput(true);
    con.setRequestProperty("Content-Type","application/octet-stream");
    con.setRequestMethod("POST");
    outputToServlet = new ObjectOutputStream(con.getOutputStream());
    outputToServlet.writeObject(itemType);// itemType is an object which implements serializable interface
    outputToServlet.flush();
    outputToServlet.close();
    con.disconnect();
    catch(Exception ex)
    ex.printStackTrace();
    On the servlet side the code is:
    System.out.println("doPost is being calling now");
    ObjectInputStream inputFromApplet = null;//objStream
    ItemType itemType = null;
    try {
    // get an input stream from the applet
    inputFromApplet = new ObjectInputStream(request.getInputStream());
    // read the serialized itemType data from applet
    itemType = (ItemType)(inputFromApplet.readObject());
    inputFromApplet.close();
    catch (Exception e)
    e.printStackTrace();
    But the doPost doesn't be invoked at all, does anybody have any idea?
    Please help, and Thanks
    Billsend

    Hi friends,
    It seems I have finally found the answer to calling doPost() of HttpServlet from applet. Espcially for those who were working on jdk1.3 or previous would notice that after moving to a higher jsdk version, their code has suddenly stopped calling the doPost() method in servlet the answer to this is that remember to call the getResponseMessage() And disconnect() method on the HttpURLConnection after closing the outputStream on it.
    This is a sample code to Send the object from applet to servlet in order to invoke doPost() method at the servlet.
    //servletGetUser is a url in the form => http://host:port/contextroot/servletName.
         URL DBSrvlet = new URL(servletGetUser);
         HttpURLConnection SrvletConnection = (HttpURLConnection) DBSrvlet.openConnection();
         SrvletConnection.setDoOutput(true);
         SrvletConnection.setRequestMethod("POST");
         SrvletConnection.setUseCaches(false);      
         SrvletConnection.setDefaultUseCaches(false);
         SrvletConnection.setRequestProperty("Content-type","application/x-www-form-urlencoded");
         ObjectOutputStream outputToServlet = new ObjectOutputStream(SrvletConnection.getOutputStream());
         outputToServlet.writeObject(tAdmin);
    outputToServlet.flush();     
         outputToServlet.close();
         // Remember your doPost() method gets fired actually by these last 2 lines.
    SrvletConnection.getResponseMessage()
         SrvletConnection.disconnect();
    Do let me know if this works,
    Thanks,
    Himanshu B.

  • Controller Is Being Called Twice - Why???

    I think this is going to be a complicated question to answer but I'll try to explain what's going on as best I can. The basic problem I'm having is that the controller class gets called twice for some reason (instead of once) and I have no idea why. I type in a URL in my browser that goes to a JSP page called �myJsp.jsp�. Basically all that page contains is this...
    <tiles:insert definition =�my.tile� flush=�true�/>In my tiles-defs.xml file I have the following listing...<definition
    name="my.tile"
    path="SomeOtherJsp.jsp"
    controllerClass="x.y.z.MyController">
    </definition>
    x.y.z.MyController.java makes some calls to a DAO to retrieve data. MyController.java then puts that data into the requestScope for the JSP below to access...
    SomeOtherJsp.jsp has nothing special in it although it DOES contain a link to myJsp.jsp (and, somehow, it's like this link is being clicked even though I'm not clicking it).
    <a href="myJsp.jsp?someParam=<c:out value="${requestScope.someValue}"/>">Click Here To Do Something</a>If anyone can help I'd greatly appreciate it. By the way, I spoke to someone else who mentioned that I should turn this kind of thing into a struts action instead of doing a deletion within a controller class. I am going to refactor my code to do this. However, I'm still curious to know the answer to my question. Maybe it will help me get a better understanding of exactly what's going on in the world of servlets. :)

    Hi Shiv, <br><br>
    Yes I have placed System.out.println...and a debug point ...<br>
    super.processRequest(pageContext, webBean);<br>
    OAApplicationModule am = pageContext.getApplicationModule(webBean); <br>
    // String personId="13477";<br>
    // Serializable[] parameters = { personId };<br>
    if (!pageContext.isFormSubmission()) {     <br>
    am.invokeMethod("createEmployeeRow", null);<br>
    }<br>
    //am.invokeMethod("initDetails",parameters);<br>
    System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!IN Process Request"); <br>
    debug point is at String personID="13477"....<br><br>
    Thanks<br>Soujanya

  • ProcessAction for portlet being called twice

    I am creating jsr-168 portlets on sun studio 8 . the problem that i am facing is that ProcessAction method seems to be called twice. Yet when i actually deploy the portlet on sun portal server 6 . They run well (i.e the method is called only once) . Can any body explain this? is this a bug or some configuration error at my development simulation server ? please help.
    regards
    Kimi

    This is a known bug indeed. If I'm not mistaken a fix for it was released as part of Update Pack 3 for JSE 8. Please check whether the update is available on the Update Center. Tools->Update Center

  • Graphing: RollOverBoxItemRenderer being called twice

    i have an mx:AreaSeries, and an mx:LineSeries, and an
    itemRenderer in the mx:LineSeries, but for some reason, the
    RollOverBoxItemRenderer is being called on both the AreaSeries and
    the LineSeries - even though it's only in the LineSeries. any ideas
    as to why??

    i have an mx:AreaSeries, and an mx:LineSeries, and an
    itemRenderer in the mx:LineSeries, but for some reason, the
    RollOverBoxItemRenderer is being called on both the AreaSeries and
    the LineSeries - even though it's only in the LineSeries. any ideas
    as to why??

  • NeedHelp -- Process Request is being called twice ?

    Hi,<br>
    Process Request is called twice and row is intialized twice and row is inserting twice in table....<br>
    Thanks<br>
    soujanya

    Hi Shiv, <br><br>
    Yes I have placed System.out.println...and a debug point ...<br>
    super.processRequest(pageContext, webBean);<br>
    OAApplicationModule am = pageContext.getApplicationModule(webBean); <br>
    // String personId="13477";<br>
    // Serializable[] parameters = { personId };<br>
    if (!pageContext.isFormSubmission()) {     <br>
    am.invokeMethod("createEmployeeRow", null);<br>
    }<br>
    //am.invokeMethod("initDetails",parameters);<br>
    System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!IN Process Request"); <br>
    debug point is at String personID="13477"....<br><br>
    Thanks<br>Soujanya

  • DoGet() method is being called every 3inutes repetitively in servlet

    HI,
    There are 2 managed servers in one unix box.
    i have one war application deployed in cluster level. This war application will search the logs and will give particular content as a result.
    The Jsp page will send the request and it is able to get the correct results if the operation completes within 3 minutes. if there are so many logs, it is giving unreliable results as war application is sending the request again and again in the interval of 3 mins.
    Request parameters are getting by servlet, and this servlet will create the unix shellscript in background and it will execute in a box.
    0-3 mins 1st .sh creating and executing..
    3-6 mins 2nd .sh creats and starts the execution, once the 1 one is completed...
    its becomes infinite loop...
    after some time Browser is going to diagnostic error state..
    i did debugging there i can see doGet method of servlet is being called for every 3 minutes..
    to avoid this i tried to give some parameters in weblogic.xml file...but its not working..
    please fine below weblogic.xml file
    ====================================
    <?xml version='1.0' encoding='UTF-8'?>
    <weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.2/weblogic-web-app.xsd">
    <session-descriptor>
    </session-descriptor>
    <jsp-descriptor>
    <page-check-seconds>-1</page-check-seconds>
    <debug>true</debug>
    </jsp-descriptor>
    <container-descriptor>
    <resource-reload-check-secs>-1</resource-reload-check-secs>
    <servlet-reload-check-secs>-1</servlet-reload-check-secs>
    <prefer-web-inf-classes>true</prefer-web-inf-classes>
    </container-descriptor>
    <logging>
    <log-filename>/wls_domains/b2borap2/application_MT/logs/messagetracker.log</log-filename>
    </logging>
    </weblogic-web-app>
    =======================================================
    and web.xml file is
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:javaee="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <listener>
    <listener-class>
    com.tm.messagetracker.listeners.MTrackerSession
    </listener-class>
    </listener>
    <servlet>
    <servlet-name>Controller</servlet-name>
    <servlet-class>com.tm.messagetracker.Controller</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>Controller</servlet-name>
    <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <session-config>
    <session-timeout>30</session-timeout>
    </session-config>
    <mime-mapping>
    <extension>txt</extension>
    <mime-type>text/plain</mime-type>
    </mime-mapping>
    <mime-mapping>
    <extension>html</extension>
    <mime-type>text/html</mime-type>
    </mime-mapping>
    <mime-mapping>
    <extension>htm</extension>
    <mime-type>text/html</mime-type>
    </mime-mapping>
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
    </welcome-file-list>
    </web-app>
    =========================================
    please find the servlet code..
    public class Controller extends HttpServlet
    public void init()
    public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
         System.out.println("Iam at doGet");
    res.setContentType("text/html");
    HttpSession session = req.getSession (false);
    if (session==null) {
         // We Send a Redirect
         res.sendRedirect("./../pages/login.jsp");
    //HttpSession session = req.getSession(true);
    boolean loginTravelled = new Boolean((String)session.getAttribute("loginTravelled")).booleanValue();
    UserVerification uv = new UserVerification();
    MTUtils mTUtils = new MTUtils();
    Properties systemProps = SerializeProperties.doLoad();
    int noOFrecordsPerPage = 10;
    if (loginTravelled)
         System.out.println("loginTravelled value :"+loginTravelled);
    String pageId = req.getParameter("pageId");
    String actionId = req.getParameter("actionId");
    if (actionId.equals("logout"))
    session.removeAttribute("CompleteSearchRecords");
    session.removeAttribute("DisplaySearchRecords");
    session.invalidate();
    System.gc();
    res.sendRedirect("./../pages/login.jsp");
    else if (pageId.equals("faq"))
    if (actionId.equals("homepage"))
    System.gc();
    res.sendRedirect("./../pages/login.jsp");
    else if (actionId.equals("download"))
    String fileName = req.getParameter("fileName");
    String originalFileName = req.getParameter("originalFileName");
    doDownload(req, res, fileName, originalFileName);
    else if (pageId.equals("login"))
    if (actionId.equals("downloads"))
    List downloadListRecords = null;
    try
    downloadListRecords = DownloadableRecords.getDownloadableRecords(new File(systemProps.getProperty("faq")));
    catch (Exception e)
    e.printStackTrace();
    session.setAttribute("DownloadListRecords", downloadListRecords);
    res.sendRedirect("./../pages/downloads.jsp");
    else if (actionId.equals("userlogin"))
    String userId = req.getParameter("uname").trim();
    String password = req.getParameter("passwd").trim();
    if ((userId != null) && (userId.length() > 0) && (password != null) && (password.length() > 0))
    if ((userId.equals("superadmin")) && (password.equals("superadmin")))
    res.sendRedirect("./../pages/admin.jsp");
    String userAuthMsg = UserVerification.verifyUser(userId, password);
    if (userAuthMsg.equals("adminuser"))
    res.sendRedirect("./../pages/admin.jsp");
    else if (userAuthMsg.equals("guestuser"))
    res.sendRedirect("./../pages/search.jsp");
    else if (userAuthMsg.equals("wrongpassword"))
    res.sendRedirect("./../pages/login.jsp?userAuthDispMsg=Sorry wrong password");
    else if (userAuthMsg.equals("unauthorizeduser"))
    res.sendRedirect("./../pages/login.jsp?userAuthDispMsg=User is not Authorized ");
    else if ((userAuthMsg.equals("adminpropsNotFound")) || (userAuthMsg.equals("guestpropsNotFound")))
    res.sendRedirect("./../pages/error.jsp?userAuthDispMsg=user configurations not found , Please contact admin");
    else
    res.sendRedirect("./../pages/login.jsp?userAuthDispMsg=UserName or password cannot be null");
    else if (pageId.equals("adminPage"))
    if (actionId.equals("adduser"))
    CommonProperties adminProps = MTrackerProperties.getAdminProps();
    CommonProperties guestProps = MTrackerProperties.getGuestProps();
    String userId = req.getParameter("adduname").trim();
    String password = req.getParameter("passwd").trim();
    String userAuthMsg = uv.verifyUser(userId);
    if (userAuthMsg.equals("adminuser"))
    res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=Admin user with name exists");
    else if (userAuthMsg.equals("guestuser"))
    res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=Guest user with name exists");
    else
    String userType = req.getParameter("usertype").trim();
    if (userType.equals("admin"))
    adminProps.addProperty(userId, password);
    res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=User " + userId + " added successfully");
    else
    guestProps.addProperty(userId, password);
    res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=User " + userId + " added successfully");
    else if (actionId.equals("deleteuser"))
    CommonProperties adminProps = MTrackerProperties.getAdminProps();
    CommonProperties guestProps = MTrackerProperties.getGuestProps();
    String userId = req.getParameter("deluname").trim();
    String userAuthMsg = uv.verifyUser(userId);
    if (userAuthMsg.equals("adminuser"))
    adminProps.deleteProperty(userId);
    res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=Admin user " + userId + " deleted");
    else if (userAuthMsg.equals("guestuser"))
    guestProps.deleteProperty(userId);
    res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=Guest user " + userId + " deleted");
    else
    res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=User " + userId + " does not exists ");
    else if (actionId.equals("updatescript"))
    String perlScriptLoc = req.getParameter("perlloc").trim();
    SerializeProperties.doSave(perlScriptLoc);
    try
    Thread.sleep(2500L);
    catch (InterruptedException e) {
    e.printStackTrace();
    res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=Perl script location updated with -> " + perlScriptLoc);
    else if (actionId.equals("updatepropertyfile"))
    String propfileLoc = req.getParameter("proploc").trim();
    SerializeProperties.doSave(propfileLoc);
    try
    Thread.sleep(2500L);
    catch (InterruptedException e) {
    e.printStackTrace();
    res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=Property file location updated with -> " + propfileLoc);
    else if (actionId.equals("searchLink"))
    res.sendRedirect("./../pages/search.jsp");
    if (actionId.equals("cleanup"))
    String resultsDir = systemProps.getProperty("results");
    mTUtils.deleteFiles(new File(resultsDir), 24);
    res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=Cleanup Done !!!");
    else if (pageId.equals("searchPage"))
         System.out.println("Start searching process Here");
         if (actionId.equals("search"))
         System.out.println("Started searching process");
    String tboxValue = req.getParameter("tbox");
    String tareaValue = req.getParameter("tarea");
    String SearchString = "";
    String auditEnable = req.getParameter("audit");
    String errorEnable = req.getParameter("error");
    String debugEnable = req.getParameter("debug");
    String srchStartDate = req.getParameter("srchstartDate");
    String srchEndDate = req.getParameter("srchendDate");
    String srchInZipFile = "";
    if (req.getParameter("srchInZipFile") != null) {
    srchInZipFile = req.getParameter("srchInZipFile");
    String mode = req.getParameter("inputmode");
    try
    if (req.getParameter("recordsPerPage") != null)
    noOFrecordsPerPage = new Integer(req.getParameter("recordsPerPage")).intValue();
    catch (Exception e)
    res.sendRedirect("./../pages/error.jsp?userAuthDispMsg=recordsPerPage should be a number");
    if (mode.equals("single"))
    SearchString = tboxValue;
    else
    SearchString = tareaValue;
    String inputDir = systemProps.getProperty("inputs");
    String resultsDir = systemProps.getProperty("results");
    String inputFileName = new Integer(mTUtils.getRandom()).toString();
    File inputParams = new File(inputDir + "/" + inputFileName + ".properties");
    File inputTxt = new File(inputDir + "/" + inputFileName + ".txt");
    synchronized (inputParams) {
         System.out.println("inputParams"+inputParams);
    synchronized (inputTxt)
         System.out.println("inputtxt"+inputTxt);
    boolean saved = false;
    CommonProperties singleSerProps = new CommonProperties(inputParams);
    Properties searchProps = new Properties();
    searchProps.setProperty("search_from_date", srchStartDate);
    searchProps.setProperty("search_to_date", srchEndDate);
    searchProps.setProperty("force_zip_search", srchInZipFile);
    if ((SearchProperties.saveSingeSearchProps(singleSerProps, searchProps)) && (SearchProperties.saveSearchFile(inputTxt, SearchString)))
    if (mTUtils.genarateScript(auditEnable, debugEnable, errorEnable, srchInZipFile, inputFileName))
    if (mTUtils.runScript("sh", inputFileName))
    List tRecords = null;
    TrackingLogReader treader = new TrackingLogReader();
    try
    tRecords = treader.getRecords(new File(resultsDir), inputFileName);
    catch (Exception e)
    e.printStackTrace();
    if (tRecords == null)
    tRecords = new ArrayList();
    tRecords.add("No Records Found");
    String backEnb = "";
    String nextEnb = "";
    int fromRec = 0;
    int toRec = 0;
    if (tRecords.size() > noOFrecordsPerPage)
    toRec = noOFrecordsPerPage;
    backEnb = "false";
    nextEnb = "true";
    else
    toRec = tRecords.size();
    backEnb = "false";
    nextEnb = "false";
    List subList = tRecords.subList(fromRec, toRec);
    session.setAttribute("CompleteSearchRecords", tRecords);
    session.setAttribute("DisplaySearchRecords", subList);
    session.setAttribute("fromRec", new Integer(fromRec));
    session.setAttribute("toRec", new Integer(toRec));
    session.setAttribute("nextEnb", nextEnb);
    session.setAttribute("backEnb", backEnb);
    session.setAttribute("recsPerPage", new Integer(noOFrecordsPerPage));
    res.sendRedirect("./../pages/SearchResults.jsp");
    else {
    res.sendRedirect("./../pages/error.jsp?userAuthDispMsg=Problem in calling PERL system , Please contact admin");
    else
    res.sendRedirect("./../pages/error.jsp?userAuthDispMsg=Script not generated , Please contact admin");
    else
    res.sendRedirect("./../pages/error.jsp?userAuthDispMsg=Search input directory not found, Please contact admin ");
    //inputParams.delete();
    //inputTxt.delete();
    else if (pageId.equals("searchresults"))
    noOFrecordsPerPage = ((Integer)session.getAttribute("recsPerPage")).intValue();
    if (actionId.equals("newSearch"))
    session.removeAttribute("CompleteSearchRecords");
    session.removeAttribute("DisplaySearchRecords");
    session.removeAttribute("fromRec");
    session.removeAttribute("toRec");
    session.removeAttribute("recsPerPage");
    System.gc();
    res.sendRedirect("./../pages/search.jsp");
    else if (actionId.equals("first"))
    List completeRecords = (List)session.getAttribute("CompleteSearchRecords");
    int fromRec = 0;
    int toRec = 0;
    String backEnb = "";
    String nextEnb = "";
    if (completeRecords.size() > noOFrecordsPerPage)
    toRec = noOFrecordsPerPage;
    backEnb = "false";
    nextEnb = "true";
    else
    toRec = completeRecords.size();
    backEnb = "false";
    nextEnb = "false";
    List subList = completeRecords.subList(fromRec, toRec);
    session.setAttribute("CompleteSearchRecords", completeRecords);
    session.setAttribute("DisplaySearchRecords", subList);
    session.setAttribute("fromRec", new Integer(fromRec));
    session.setAttribute("toRec", new Integer(toRec));
    session.setAttribute("nextEnb", nextEnb);
    session.setAttribute("backEnb", backEnb);
    session.setAttribute("recsPerPage", new Integer(noOFrecordsPerPage));
    res.sendRedirect("./../pages/SearchResults.jsp");
    else if (actionId.equals("last"))
    List completeRecords = (List)session.getAttribute("CompleteSearchRecords");
    int fromRec = 0;
    int toRec = completeRecords.size();
    String backEnb = "";
    String nextEnb = "";
    if (noOFrecordsPerPage > completeRecords.size())
    fromRec = 0;
    backEnb = "false";
    nextEnb = "false";
    else
    fromRec = completeRecords.size() - noOFrecordsPerPage;
    backEnb = "true";
    nextEnb = "false";
    List subList = completeRecords.subList(fromRec, toRec);
    session.setAttribute("CompleteSearchRecords", completeRecords);
    session.setAttribute("DisplaySearchRecords", subList);
    session.setAttribute("fromRec", new Integer(fromRec));
    session.setAttribute("toRec", new Integer(toRec));
    session.setAttribute("nextEnb", nextEnb);
    session.setAttribute("backEnb", backEnb);
    session.setAttribute("recsPerPage", new Integer(noOFrecordsPerPage));
    res.sendRedirect("./../pages/SearchResults.jsp");
    else if (actionId.equals("back"))
    List completeRecords = (List)session.getAttribute("CompleteSearchRecords");
    int fromRec = ((Integer)session.getAttribute("fromRec")).intValue();
    int toRec = ((Integer)session.getAttribute("toRec")).intValue();
    toRec = fromRec;
    if (fromRec - noOFrecordsPerPage > 0)
    session.setAttribute("backEnb", "true");
    fromRec -= noOFrecordsPerPage;
    else
    fromRec = 0;
    session.setAttribute("backEnb", "false");
    session.setAttribute("nextEnb", "true");
    session.setAttribute("fromRec", new Integer(fromRec));
    session.setAttribute("toRec", new Integer(toRec));
    List subList = completeRecords.subList(fromRec, toRec);
    session.setAttribute("DisplaySearchRecords", subList);
    res.sendRedirect("./../pages/SearchResults.jsp");
    else if (actionId.equals("next"))
    List completeRecords = (List)session.getAttribute("CompleteSearchRecords");
    int fromRec = ((Integer)session.getAttribute("fromRec")).intValue();
    int toRec = ((Integer)session.getAttribute("toRec")).intValue();
    fromRec = toRec;
    if (toRec + noOFrecordsPerPage <= completeRecords.size())
    session.setAttribute("nextEnb", "true");
    toRec += noOFrecordsPerPage;
    else
    toRec = completeRecords.size();
    session.setAttribute("nextEnb", "false");
    session.setAttribute("backEnb", "true");
    session.setAttribute("fromRec", new Integer(fromRec));
    session.setAttribute("toRec", new Integer(toRec));
    List subList = completeRecords.subList(fromRec, toRec);
    session.setAttribute("DisplaySearchRecords", subList);
    res.sendRedirect("./../pages/SearchResults.jsp");
    else if (actionId.equals("download"))
    String fileName = req.getParameter("fileName");
    String originalFileName = req.getParameter("originalFileName");
    doDownload(req, res, fileName, originalFileName);
    else
    res.sendRedirect("./../pages/login.jsp?userAuthDispMsg=Invalid USER");
    public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    doGet(req, res);
    private void doDownload(HttpServletRequest req, HttpServletResponse resp, String filename, String original_filename)
    throws IOException
    File f = new File(filename);
    int length = 0;
    ServletOutputStream op = resp.getOutputStream();
    ServletContext context = getServletConfig().getServletContext();
    String mimetype = context.getMimeType(filename);
    resp.setContentType(mimetype != null ? mimetype : "application/octet-stream");
    resp.setContentLength((int)f.length());
    resp.setHeader("Content-Disposition", "attachment; filename=\"" + original_filename + "\"");
    byte[] bbuf = new byte[10240];
    DataInputStream in = new DataInputStream(new FileInputStream(f));
    while ((in != null) && ((length = in.read(bbuf)) != -1))
    op.write(bbuf, 0, length);
    in.close();
    op.flush();
    op.close();
    =========================
    anyone please help me on above......Thanks in advance..

    Hi jleech,
    Thanks for the reply. But deleting all the temporary internet files as also the history files does not seem to have an effect. the doFilter is being called only at the second request. or did i miss anything??
    Please help. unable to complete the assignment because of this.
    Thank You,
    Phani Kanuri

  • DoGet called twice on Tomcat Startup

    Hi,
    I have a problem with my Servlet doGet/doPost method being called twice (sometimes three times) on Tomcat 5 startup with J2SE 1.4 and Java SE 6. This problem happens on both, Firefox and Internet Explorer.
    I only have one Servlet (called ServletFrontController) in my descriptor, since I decided to use the Front Controller Pattern. This Servlet extends from a "base Servlet" which has all the init configurations. My deployment descriptor looks like this (I also have mappings which I haven't included here):
        <servlet>
            <servlet-name>MainServlet</servlet-name>
            <servlet-class>com.myprogram.ServletFrontController</servlet-class>
            <init-param>
                <param-name>config</param-name>
                <param-value>application.properties</param-value>
            </init-param>
        </servlet>My doGet / doPost / doHead methods from the base Servlet just delegate to the ServletFrontController "main" method, like this:
    public final void doGet(HttpServletRequest request, HttpServletResponse response) {
            try {
                process(request, response);
            } catch (Exception e) {
                handleException(e, request, response);
    }Does anyone had this problem and know why this could happen?
    Martin

    All,
    See post: [http://forum.java.sun.com/thread.jspa?threadID=720175|http://forum.java.sun.com/thread.jspa?threadID=720175]
    Might help.
    - JFK

  • Sprint -- Form being submitted twice, IE only.

    Up front I'll state that this probably has nothing to do with Java, but I'll throw it out here just in case.
    On a particular page, when we put 19 or more items into a list in a form, when we submit that form, the onSubmit method of our subclass of org.springframework.web.servlet.mvc.SimpleFormController is getting called twice.
    This happens in IE, but not in Opera or Firefox.
    Because of the browser-specific nature of this problem, I'm pretty sure it's not related to Java, but if anybody has seen something like this before or has an idea where to start looking, I'd be very appreciative.
    This stuff was developed before my time, and I just started looking at it, so I'm not very familiar with it. It uses javascript, freemarker, and spring, none of which I'm familiar with. The only detail I've found for sure is that onSubmit is being called twice, and I'm a bit buggered as to where to look now.
    Thanks,
    Jeff

    Do the forms get submitted by using a javascript call to form.submit()?
    And is that javascript function called from an onclick event on an input type="submit"?
    That can (and does) result in a double submit in IE.
    It does not in firefox.
    Heres a quick jsp page that demonstrates this:
    <%! int count = 0; %>
    <html>
    <% System.out.println("Running..." + count++ + "Browser = " + request.getHeader("user-agent")); %>
    <script>
      function doStuff(button){
                     // submit via javascript
           button.form.submit();
    </script>
    <form>
      <input type="text" name="a1"/>
      <input type="text" name="a2"/>
      <input type="submit" onclick="doStuff(this)"/>
    </form>
    </html>This triggers two submits
    - one for calling form.submit();
    - one for pressing the submit button.
    To fix - remove/cancel one of the submission events, any of the following should work:
    - change the <input type="submit"> to an <input type="button">
    - change the onclick event to be "doStuff(); return false": returning false from an onclick event handler cancels the event - in this case it would cancel form submission.
    - remove the form.submit() javascript call
    Cheers,
    evanfets

  • Parsing code called twice

    Somehow my code is being called twice with the result that everything has the same name twice (multiple names are legal according to the DTD).
    My parsing code looks like this:
    public Channel getChannel(Node channelnode)
    Channel channel;
    NodeList channelchildren;
    Element channelelement;
    channelelement = (Element)channelnode;
    if(channelelement.hasAttribute("id"))
    channel = new Channel(channelelement.getAttribute("id"));
    channelchildren = channelnode.getChildNodes();
    for(int i = 0 ; i < channelchildren.getLength() ; i++)
    if(channelchildren.item(i).getNodeType() == Node.ELEMENT_NODE)
    if(channelchildren.item(i).getNodeName().equals(("display-name")))
    channel.addDisplayname(getDisplayname(channelchildren.item(i)));
    if(channelchildren.item(i).getNodeName().equals(("icon")))
    if(channelchildren.item(i).getNodeName().equals(("url")))
    else
    channel = null;
    return channel;
    public String getDisplayname(Node displaynamenode)
    Element displaynameelement;
    Node displayname;
    displaynameelement = (Element)displaynamenode;
    displayname = displaynamenode.getFirstChild();
    if(displaynameelement.hasAttribute("lang"))
    return displayname.getNodeValue();
    else
    return displayname.getNodeValue();
    The code above is used to parse part of this tag in my XML file:
    <channel id="001.tv.tv2.dk">
    <display-name>TV 2</display-name>
    <icon src="http://tv.tv2.dk/images/logo/1.gif" />
    </channel>
    The problem is that the addDisplayname in the Channel class is somehow called twice even though there is only one <display-name> tag.
    Any help figuring out what is happening will be greatly appreciated.

    I know about the second point you are making. The if-then-else statement is actually the start of further development since the <display-name> element can have a lang attribute and I have to deal with it, but for now I ignore it since it is extremely rarely used and other things are more important.
    I had thought about the case that you mention with multiple calls of getChannel() but my debug output suggests that it is not the case. The method getChannel() returns a Channel object, which has a toString() method, and that object is given as argument to System.out.println() and never saved anywhere.
    The toString() method of the Channel object looks like this:
    public String toString()
    String tmp = new String();
    tmp += "display-name: " + displaynames.get(0);
    for(String name : displaynames)
    tmp += ", " + name;
    return tmp;
    With an output that look like this for the XML example given in my original post: display-name: TV 2, TV 2
    With this output I don't see how multiple calls of getChannel() can be the cause, since multiple calls should give multiple Channel objects and multiple lines of output.

  • EJB 3.1 @Singleton with @Startup causes @PostConstruct to be called twice...

    I have been working on initializing a some elements in the @PostConstruct annotated method within an EJB that is already annotated as @Singleton.  I decided that I wanted the initialization to be done when the EJB is deployed so I added the @Startup.  Both the constructor and @PostConstruct method is getting called twice.  Can someone please explain to me why it appears the EJB is being initialized twice and if there is a way to prevent the @PostConstruct method from being called twice?
    Many thanks,
    - Joe

    Is this with GlassFish?

  • EO Validation method called twice

    Hi,
    I have written an EO based field Validation method. But the problem is it is being called twice. First time ,it is validating correctly. But the second time it is not taking the field value and giving the error
    I have included it like this in my jspx.
    <af:inputText value="#{bindings.SubOrgName.inputValue}"
    label="#{bindings.SubOrgName.label}"
    required="#{bindings.SubOrgName.mandatory}"
    columns="#{bindings.SubOrgName.displayWidth}"
    binding="#{backing_Org.inputText3}"
    id="inputText3"
    rows="1">
    <af:validator binding="#{bindings.SubOrgName.validator}"/>
    </af:inputText>
    Please help.

    Thanks for sharing! ;-)

Maybe you are looking for

  • Recording from Vinyl Tapes to Zen Visio

    1 ) Is it possible to transfer music directly from my Vinyl Cassettes to Zen Vision M (60GB)? 2) Can I use External mic for voice recording instead of inbuilt mic? Any special accessories required for the above tasks and their availability (Creative

  • Single Payment Document for F110

    Dear SAP Expert, I have a scenario where I wanted to create only 1 payment document during automatic run payment via F110 for all selected vendors. Currently each the payment document was created separately by vendor. Is there any configurations that

  • 4215 IPS 5.x analysis engine woes

    I've got about 20 4215's that i'm upgrading from 4.1 to 5.x Like everyone else I've had nothing but problems with the 5.1x (analysis engine just stops running) I've tried upgrading using a brand new image, using both the 5.0(1) and 5.0(2) images. How

  • Failed first backup cannot select timecapsule - help

    Hello, i have followed all instructions to set up my time capsule but time machine was unable to do a automatic first backup. I am unable to see the time capsule as a source for my backup I can only see a share-folder with the name data. can somebody

  • How to change mac desktop icons

    I want to change my Macintosh HD icon to an icon of iMac. Where do I find this and do it? I also want to change other HD icons on desktop - how is this done in Mavericks? Thanks, Don