DoPost() and doGet() method calling

Hi All,
What is the purpose of calling the doGet() method inside of doPost() instead of calling it directly.
          doPost(HttpServletRequest request, HttpServletResponse response){
                                doGet(request,response);
            why we are calling the doGet() method like thisThanks in Advance,
mahes

Seemingly the post and the get do exactly the same thing, so to avoid duplicate code, (s)he just simply had one call the other.
However, you shouldn't really do it this way. You should break out the parts of the methods that are the same into new methods, and call these new methods from both the post and get methods. That will allow the two methods to handle some other things slightly differently. I.E. the get method is not suppossed to cause side effects (i.e. you are not suppossed to change any data when using a get method) whereas post methods can.

Similar Messages

  • Are the service(), doPost() and doGet() methods THREAD-SAFE?

    Please Let Me know If service(), doPost() and doGet() are Thread-safe. If they are not thread safe, How to make them thread-safe?

    Please Let Me know If service(), doPost() and doGet() are Thread-safe. They are not.
    If they are not thread safe, How to make them thread-safe?The best way is to avoid writing code that depends on a servlet's thread safety; i.e., no servlet instance variables - keep everything local to the method. Else, you'll want to learn about synchronization.
    [JavaWorld article - Write thread-safe servlets|http://www.javaworld.com/javaworld/jw-07-2004/jw-0712-threadsafe.html].
    ~

  • Servlet with dopost and main() methods

    I have pre-existing servlet code for maintenance purposes.
    It received a request by POST action from the client. This class also has main() method where class is instasiated and processed.
    Can anyone help me understand reason for having dopost and main() methods.
    TIA

    Before the days of JUnit developers would write a main method for a class as a way to test the class. Some older developers still do it. I know because I am dealing with the problem now.

  • Difference between doPost and doGet

    Can anyone tell the diffence between the following 2 implementations.
    Case -1
    doPost{
    doGet();
    Case - 2
    doGet{
    doPost();
    }

    doGet has its own constraint which you would know. Other than that there wont be any data truncation...
    And regarding the first question u have asked, I am not too sure what will happen. I think the Server will respond saying "recursive call done". I think this will create Memory Problems

  • Working with class based exception and dynamic method calls

    Hi Gurus,
    we just changed out ERP from EHP6 to EHP7.
    Since we did so we are facing an issue with an Z-Report we are using quite often.
    This reports looks up Workitems and executes the according methods so that we can go into debugging if we were facing any problems or errors.
    since the EHP Upgrade this statement has problems:
      data:        lt_parmbind   type abap_parmbind_tab,         lt_excpbind   type abap_excpbind_tab,         lo_runtime    type ref to object.     call method lo_runtime->(iv_cls_method)       parameter-table       lt_parmbind       exception-table       lt_excpbind.this CALL METHOD Statement has Problem with the Exception Table. We are quite often getting DYN_CALL_METH_EXCP_NOT_FOUND short dumps with Exception "CX_SY_DYN_CALL_EXCP_NOT_FOUND".
    The system has problems handling the content of lt_excpbind. if i clear this table the CALL METHOD statement works fine.
    AS an example we are trying to call /IDXGC/CL_PD_PROCESS_STEPS-->CREATE_DATA. This method has 2 exceptions
    /IDXGC/CX_PROCESS_ERROR
    Process Layer Exception
    CX_BO_TEMPORARY
    Temporary Business Exception
    The Content of LT_EXCPBIND is
    INDEX
    NAME
    VALUE
    2
    /IDXGC/CX_PROCESS_ERROR
    1
    2
    CX_BO_TEMPORARY
    2
    From my point of view the Problem ist, that they are marked as "class based". I think so because if you looked up the SAP Help for the EXCEPTION-TABLE Statement it is written that is statement only works for none-classbased exception.
    I think that restriction is quiet clear. But what i am wondering about is.. that restriction also exists for EHP6. And in EHP6 it work. Does anyone know why? Or how i can change me CALL METHOD Statement that i will work again?
    Best Regards
    Udo

    Class-based exceptions must be caught using try/catch statement.
    Calling dynamically a method catchable exceptions are:
    CX_SY_DYN_CALL_EXCP_NOT_FOUND
    CX_SY_DYN_CALL_ILLEGAL_CLASS 
    CX_SY_DYN_CALL_ILLEGAL_METHOD
    CX_SY_DYN_CALL_PARAM_MISSING 
    CX_SY_DYN_CALL_PARAM_NOT_FOUND 
    CX_SY_REF_IS_INITIAL
    Anyway catching cx_root (as shown by Matthias) will catch everything is catchable.

  • The dot operator and a method called 'cons'?

    I'm trying to write a static method that takes a list of things (array or List objects).
    It returns another list based on the first but changed by some rule.
    I am told that I have:
    non-static methods - head, tail, cons, isEmpty
    a static method - empty (creates a new list)
    I have to assume (was not told) that:
    'head' returns the object at the head of our list
    'tail' returns the next object from the one we are looking at
    'isEmpty' returns a boolean if nothing there.
    and lastly:
    'cons' which meant nothing to me but I have been advised that it probably does something like concatonates or adds to the end of.
    1. Is this name (cons) in popular use & what does a method with that name usually do?
    2. Assuming I'm right and I want to step through adding the elements in turn.
    Which do you think would be the right way to add/append/concatonate (or whatever) the current element to my newList?
    newList = newList.cons(lst.head()); or
    newList = lst.head().cons(newList);('lst' being the particular list we're looking at)
    Is there something else I should have written?
    For some reason I find this very confusing!

    Yes, something like that :)
    Now let's see what we have to do...
    1. if the list is empty we can just return it.
    2. if the head of the list is the same as 'target' and n is 0 (or 1), take the tail of the list, add 'alternate' to it, and return it. I.e. return lst.tail().cons(alternate); (syntax depends on what arguments your cons takes, I guess)
    3. if the head of the list matches again but n > 0 (or 1), decrement n by one and recurse with the tail, add head to the result; return changeNth(lst.tail(), ...., n-1).cons(lst.head())
    4. else it is safe to recurse with the tail; return changeNth(lst.tail(), .....).cons(lst.head())
    The code with Lots of Idiotic Silly Parentheses would look a bit like(defun changeNth (lst target alternate n)
      (cond
        ((null lst) lst)
        ((equal target (first lst))
          (if (= n 0)
            (cons alternate (rest lst))
            (cons (first lst)
              (changeNth (rest lst) target alternate (- n 1)))))
        (t (cons (first lst) (changeNth (rest lst) target alternate n)))))

  • Weblogic shutdown and MDB method calls

    Hi,
    We have message driven beans deployed on Weblogic 7.0.2 server. We have a situation where there are messages pending on the JMS Queue(a persistent store is configured.) and the MDB instances will be processing the meesages from the queue. We need to restart the weblogic server at this point.
    My doubt is what happens to the messgaes which were being processed in the onMessage method of the MDB. If the server is shutdown, will these messages that were being processed also be backed up to the persistent store or will these be lost?
    There may be additional messages coming in while the server is being shutdown.
    What is the best way to shutdown the weblogic server without losing any of the messages?
    Any pointers to additional info will be highly appreciated.
    Thanks in advance,
    Amit

    <Amit Kulkarni> wrote in message news:[email protected]..
    We have message driven beans deployed on Weblogic 7.0.2 server. We have a situation where there are messages pending on the JMSQueue(a persistent store is configured.) and the MDB instances will be processing the meesages from the queue. We need to restart
    the weblogic server at this point.
    My doubt is what happens to the messgaes which were being processed in the onMessage method of the MDB. If the server is shutdown,will these messages that were being processed also be backed up to the persistent store or will these be lost?
    There may be additional messages coming in while the server is being shutdown.
    What is the best way to shutdown the weblogic server without losing any of the messages?
    Any pointers to additional info will be highly appreciated.Have a standby instance running and switch network to that instance before taking first one down or set up a full-blown cluster.
    Regards,
    Slava Imeshev

  • Request dispatcher and jsp pages called from servlets

              Given the following webapp directory structure:
              root/
              jsp/
              ..all jsp files
              web-inf/
              classes/
              /servlets
                   ..all servlet files
              /com
              ..all other java class files
              I have the jsp directory coded as: jspdir = "/jsp/" (and have tried variations
              on this theme)
              I try to open a new jsp page with the following code in a servlet in the above
              servlet directory:
                   RequestDispatcher rd;
                   rd = getServletContext().getRequestDispatcher(jspdir + myjsp.jsp);
                   rd.forward(req, res);
              rd continues to return null.
              The jsp pages are not registered in the web.xml file for this webapp, if that
              makes any difference.
              Does anyone have any suggestions?     
              [problem.txt]
              

    I create a small sample and put these files into /jsp in my war context
              it works fine, please send me the example code you are using and the
              environment description of the deployed application
              I attached my samples, that work
              Filip
              ~
              Namaste - I bow to the divine in you
              ~
              Filip Hanik
              Software Architect
              [email protected]
              www.filip.net
              "Bill Blackmon" <[email protected]> wrote in message
              news:[email protected]...
              >
              > Yes, I am able to access the jsp pages with the url listed.
              >
              > "Filip Hanik" <[email protected]> wrote:
              > >The weblogic servlet engine, is by default mapping anything that ends
              with
              > >*.jsp to be a JSP.
              > >so there shouldn't be a problem. You didn't answer my first question,
              > >are you able to access your JSP through the browser?
              > >http://localhost:7001/root/jsp/myjsp.jsp
              > >
              > >Filip
              > >
              > >--
              > >~
              > >Namaste - I bow to the divine in you
              > >~
              > >Filip Hanik
              > >Software Architect
              > >[email protected]
              > >www.filip.net
              > >"Bill Blackmon" <[email protected]> wrote in message
              > >news:[email protected]...
              > >>
              > >> The code you are reading in the message here was pasted in and
              > >> looks bad, so maybe that's what you are referring to? The dispatcher
              code
              > >is called
              > >> in the service() method of the servlet.
              > >> I have a suspicion that the jsp directory needs to be defined someplace
              > >-
              > >weblogic.properties
              > >> or web.xml?, though I don't see this in any of the examples that come
              > >with
              > >the product.
              > >>
              > >>
              > >>
              > >> "Simon Ng" <[email protected]> wrote:
              > >> >
              > >> >Hello Bill,
              > >> > Did you put a <BR>
              > >> >return;
              > >> ><BR>
              > >> >statement right after the dispatcher.forward() statement? Well, I am
              > >assuming
              > >> >your
              > >> >code is in the doPost() or doGet() methods.
              > >> >
              > >> >Simon
              > >> >
              > >> >
              > >> >"Filip Hanik" <[email protected]> wrote:
              > >> >>if you do http://localhost:7001/root/jsp/myjsp.jsp
              > >> >>
              > >> >>do you get a result?
              > >> >>
              > >> >>make sure you have the right character case on the filename.
              > >> >>
              > >> >>Filip
              > >> >>
              > >> >>--
              > >> >>~
              > >> >>Namaste - I bow to the divine in you
              > >> >>~
              > >> >>Filip Hanik
              > >> >>Software Architect
              > >> >>[email protected]
              > >> >>www.filip.net
              > >> >>"Bill Blackmon" <[email protected]> wrote in message
              > >> >>news:[email protected]...
              > >> >>>
              > >> >>> Given the following webapp directory structure:
              > >> >>> root/
              > >> >>> jsp/
              > >> >>> ..all jsp files
              > >> >>> web-inf/
              > >> >>> classes/
              > >> >>> /servlets
              > >> >>> ..all servlet files
              > >> >>> /com
              > >> >>> ..all other java class files
              > >> >>>
              > >> >>>
              > >> >>> I have the jsp directory coded as: jspdir = "/jsp/" (and have tried
              > >> >>variations
              > >> >>> on this theme)
              > >> >>> I try to open a new jsp page with the following code in a servlet
              > >in
              > >> >the
              > >> >>above
              > >> >>> servlet directory:
              > >> >>> RequestDispatcher rd;
              > >> >>> rd = getServletContext().getRequestDispatcher(jspdir + myjsp.jsp);
              > >> >>> rd.forward(req, res);
              > >> >>>
              > >> >>> rd continues to return null.
              > >> >>>
              > >> >>> The jsp pages are not registered in the web.xml file for this
              webapp,
              > >> >>if
              > >> >>that
              > >> >>> makes any difference.
              > >> >>>
              > >> >>> Does anyone have any suggestions?
              > >> >>>
              > >> >>
              > >> >>
              > >> >
              > >>
              > >
              > >
              >
              [filipInclude.jsp]
              [filipForward.jsp]
              [filip.jsp]
              

  • Invoking servlet's doGet() method on startup

    Hi Friends,
    Is there any way of invoking the servlets doGet method on server start -up.
    I am using Tomcat 4.1.18.
    I know that we can Invoke the servlet at stat-up i.e. it will invoke init() method osf servlet.But what if I want to invoke the doGet method on start - up?
    Regards
    Abhay

    The doGet will require an Request and Response object. It would be easier to remove what ever logic in the doGet you need to execute to seperate methods that can be called from both the init and doGet methods.

  • How to print a method trace to a file (first method called to the end)

    I have a tomcat war that I am deploying. I want to use some command line parameter or some tool that will show me a method trace of each method that gets executed.
    There is some static initializer in the code that starts everything in the war (the war is not a web app) but simply a process that runs in the background that does stuff.
    I want to find out what the first method called in the war is and to locate the static initializer. Having a method trace would do this because this method would be printed out first.
    After the static initializer gets called I want to see a method trace of all methods called. Having this printed to a file like Class:Method(params) would be nice.
    Even better would be some sort of tool that I could open a trace file with and see method calls in the order they were called.
    I tried several Java profiling tools but none of them show me the order (first to last) of the methods called. All I need is to see a method trace from beginning to end.
    Any help would be appreciated.

    JProbe provided almost everything I needed to see a method call trace. The method graph feature was great.
    I have a single static class with a static initializer that runs in a loop but did not know what the class name was (I inherited some code and was told about the static initializer).
    So when I fired it up in JProbe it showed me the class running off the root thread. In fact I found another static initializer that was unknown to me and another oddity as well.
    The only problem is that the method call graph is collapsed and you need to click [+] to expand every method call.
    I am told by JProbe support that there was an "expand all" option in JProbe 7.0 but it is not there in 7.1.
    Not sure why they took the time, money and energy to take a needed feature out.
    It would be great to have something that did the same thing from the command line or to be able to print a method call trace out to a file but not sure how to do this.

  • Question about method calling (Java 1.5.0_05)

    Imagine for example the javax.swing.border.Border hierarchy.
    I'm writing a BorderEditor for some gui builder, so I need a function that takes a Border instance and returns the Java code. Here is my first try:
    1 protected String getJavaInitializationString() {
    2     Border border = (Border)getValue();
    3     if (border == null)
    4         return "null";
    5
    6     return getCode(border);
    7 }
    8
    9 private String getCode(BevelBorder border) {...}
    10 private String getCode(EmptyBorder border) {...}
    11 private String getCode(EtchedBorder border) {...}
    12 private String getCode(LineBorder border) {...}
    13
    14 private String getCode(Border border) {
    15     throw new IllegalArgumentException("Unknown border class " + border.getClass());
    16 }This piece of code fails. Because no matter of what class is border in line 6, this call always ends in String getCode(Border border).
    So I replaced line 6 with:
    6     return getCode(border.getClass().cast(border));But with the same result. So, I try with the asSubClass() method:
    6     return getCode(Border.class.asSubClass(border.getClass()).cast(border));And the same result again! Then i try putting a concrete instance of some border, say BevelBorder:
    6     return getCode(BevelBorder.class.cast(border));Guess what! It worked! But this is like:
    6     return getCode((BevelBorder)border);And I don't want that! I want dynamic cast and correct method calling.
    After all tests, I give up and put the old trusty and nasty if..else if... else chain.
    Too bad! I'm doing some thing wrong?
    Thank in advance
    Quique.-
    PS: Sorry about my english! it's not very good! Escribo mejor en espa�ol!

    Hi, your spanish is quite good!
    getCode(...) returns the Java code for the given border.
    So getCode(BevelBorder border) returns a Java string that is something like this "new BevelBorder()".
    I want Java to resolve the method to call.
    For example: A1, A2 and A3, extends A.
    public void m(A1 a) {...}
    public void m(A2 a) {...}
    public void m(A3 a) {...}
    public void m(A a) {...}
    public void p() {
        A a = (A)getValue();
        // At this point 'a' could be instance of A1, A2 or A3.
        m(a); // I want this method call, to call the right method.
    }This did not work. So, i've used instead of m(a):
        m(a.getClass().cast(a));Didn't work either. Then:
        m(A.class.asSubClass(a.getClass()).cast(a));No luck! But:
        m(A1.class.cast(a)); // idem m((A1)a);Woks for A1!
    I don't know why m(A1.class.cast(a)) works and m(a.getClass().cast(a)) doesn't!
    thanks for replying!
    Quique

  • A tricky way to twick ValueBinding language to bind a method call

    Here is the scenario:
    I'd like component can bind value to method call(with parameters) to a java instance, of course including backingBean.
    I wish this solution would be useful, especially when you are working in iteration component such as ForEach, TreeView or DataTable, EL ValueBinging language might be too restricted to complex expression. This way, you can pass iteration items as parameters into a method can and return a value to you page by valuebinding language
    In JSP:
        <h:outputText value="#{Page1.callHelper[Page1]['targetMethod']['James'][Page1.callEnd]}"/>In PageBean:
         public String targetMethod(String name){
             return "Hello, " + name +"!";
        private CallHelper callHelper = new CallHelper();
         public CallHelper getCallHelper() {
              return callHelper;
         public void setCallHelper(CallHelper callHelper) {
              this.callHelper = callHelper;
         private CallEnd callEnd = new CallEnd();
         public CallEnd getCallEnd() {
              return callEnd;
         public void setCallEnd(CallEnd callEnd) {
              this.callEnd = callEnd;
         }Util classes:
    import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    import java.util.ArrayList;
    import java.util.LinkedHashMap;
    import java.util.List;
    import java.util.Map;
    public class CallHelper extends LinkedHashMap {
         private CallHelper parent;
         public Object get(Object key){
              if(key instanceof CallEnd)return getRoot().methodCall();
              else{
                   Object value = super.get(key);          
                   if(value == null){
                        value = new CallHelper();
                        put(key, value);
                        ((CallHelper)value).parent = this;
                   return value;
         public boolean containsKey(Object key){
              return true;
         public boolean realContainsKey(Object key){
              return super.containsKey(key);
        protected CallHelper getRoot(){
             CallHelper root = this;
             if(root.parent==null)return root;
             else return root.parent.getRoot();
         protected Object methodCall(){
              Object result = null;
             List callParameters = new ArrayList(2);
             listCallParameters(callParameters, this);
             if(callParameters.size()>1){
                  Object instance = callParameters.get(0);
                  String methodName = callParameters.get(1).toString();
                  List methodParameters = new ArrayList();
                  for(int i=2; i<callParameters.size(); i++){
                       methodParameters.add(callParameters.get(i));
                  Method method = findMethod(instance, methodName, methodParameters);
                  if(method != null){
                       try {
                             result = method.invoke(instance, methodParameters.toArray());
                        } catch (IllegalArgumentException e) {
                        } catch (IllegalAccessException e) {
                        } catch (InvocationTargetException e) {
              this.clear();
              return result;
         private void listCallParameters(List list, Map map){
              if(map==null || !map.keySet().iterator().hasNext())return;
              Object key = map.keySet().iterator().next();
              if(key instanceof CallEnd)return;
              list.add(key);
              listCallParameters(list, (Map)map.get(key));
         private Method findMethod(Object instance, String methodName, List parameters){
              Method result = null;
              Method[] methods = instance.getClass().getMethods();
              for(int i=0; i<methods.length; i++){
                   if(methods.getName().equals(methodName)){
                        System.out.println(methodName);
                        Class[] paraClasses = methods[i].getParameterTypes();
                        if(paraClasses.length==parameters.size()){
                             boolean match = true;
                             for(int j=0; j<paraClasses.length; j++){
                                  if(parameters.get(j)!=null && !paraClasses[j].isInstance(parameters.get(j))){
                                       match = false;
                                       break;
                             if(match){
                                  result = methods[i];
                                  break;
              return result;
    public class CallEnd {
    Improvement:
    Anyone can make it thread safety and bind callhelper and callend directly to FacesContext properties rather than each backingBean.
    Have fun!
    And feel free to contect me at:
    [email protected]
    [email protected]

    You must seperate your parameter preparing and action method calling for sure.
    It depends on what kind of parameters you need to pass in:
    1. If action method is bound to several buttons, and it just wants to know which button was clicked, you can set actionListener to prepare it for you. Because the event includes the information you need.
    2. For other kinds of parameters, you can use ValueBinding Language to bind parameter values to backingBean, then the action method(without parameters) can pick parameters up from backingBean.

  • 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

  • Problem calling servlet from doget method of another servlet

    hi,
    Iam trying to post an html form written in the doGet() method
    of a servlet to pass this information to another servlet's doPost() method. Iam giving the following URL:
    "<FORM ACTION=http://localhost:8080/examples/servlet/UpdateProcessServlet" +
    "METHOD=POST>"
    But its not happening,the error says that "the page cannot be found" The servlet is not getting called at all. would someboy please help me in this regard.
    Thanks

    #1 Iam calling servlet 2 from here
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    session=request.getSession(false);
    out.println
    (ServletUtilities.DOCTYPE +
    "<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN>"+
    "<HTML>" +
    "<BODY>" +
    "<P CLASS=LARGER>" +
    "<FORM ACTION=http://localhost:8080/examples/servlet/UpdateProcessServlet METHOD=POST>"
    "<INPUT TYPE=SUBMIT NAME=submitButton Value=submit>" +
    "</BODY> " +
    "</HTML>" );
    #2 This should get called and print me "Iam in doPost method
    public void doPost(HttpServletRequest request,HttpServletResponse response)
    throws ServletException,IOException
    url = "jdbc:odbc:Resume";
    System.out.println("Iam in doPost method");
    response.setContentType("text/html");
    out = response.getWriter();
    out.println("This is the last servlet for this project:");
    bool=false;
    check=false;
    Thank...:)

  • DoGet method is called 2 times when a switch-case statement is used

    Hello all,
    I have a servlet that, when run from browser, runs the doGet method 2 times.
    I have a switch case statement within the servlet and when I comment out this servlet, it runs 1 time as expected.
    Here is the code:
    public class RSSServlet extends HttpServlet {
        /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
         * @param request servlet request
         * @param response servlet response
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            System.out.println("CALLED SERVLET");
            response.setContentType("text/xml;charset=UTF-8");
            PrintWriter out      = response.getWriter();
            DBQueriesRSS queries = new DBQueriesRSS();
            String queryType     = request.getParameter("queryType");
            String strCount      = request.getParameter("count");
            int count            = (strCount != null && !strCount.equalsIgnoreCase("null") && strCount.length() > 0) ?
                Integer.parseInt(strCount) : 25;
             if(queryType != null && !queryType.equalsIgnoreCase("null") && queryType.length() > 0) {
                System.out.println("IN IF STATEMENT");
                switch(Integer.parseInt(queryType)) {
                    case 1 : out.println(queries.getDefault(count));System.out.println("1");       break;
                    case 11: out.println(queries.getDefault(count));System.out.println("11");       break;
                    case 21: out.println(queries.getTopDaily(count));System.out.println("21");      break;
                    case 22: out.println(queries.getTopWeekly(count));System.out.println("22");     break;
                    case 23: out.println(queries.getTopMonthly(count));System.out.println("23");    break;
                    case 24: out.println(queries.getTopYearly(count));System.out.println("24");     break;
                    case 31: out.println(queries.getTopNDailyBW(count));System.out.println("31");   break;
                    case 32: out.println(queries.getTopNWeeklyBW(count));System.out.println("32");  break;
                    case 33: out.println(queries.getTopNMonthlyBW(count));System.out.println("33"); break;
                    case 34: out.println(queries.getTopNYearlyBW(count));System.out.println("34");  break;
                    default: out.println(queries.getTopWeekly(25));System.out.println("default");    break;
                System.out.println("OUT OF SWITCH");
            System.out.println("OUT OF IF");
            out.close();
        // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
        /** Handles the HTTP <code>GET</code> method.
         * @param request servlet request
         * @param response servlet response
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            processRequest(request, response);
        /** Handles the HTTP <code>POST</code> method.
         * @param request servlet request
         * @param response servlet response
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
           processRequest(request, response);
        /** Returns a short description of the servlet.
        public String getServletInfo() {
            return "Short description";
        // </editor-fold>
    } The results from running this servlet are:
    http://localhost/proxy/RSSServlet??queryType=34&count=66
    CALLED SERVLET
    IN IF STATEMENT
    34
    OUT OF SWITCH
    OUT OF IF
    CALLED SERVLET
    IN IF STATEMENT
    34
    OUT OF SWITCH
    OUT OF IFAnyone see anything obvious?
    TIA!

    in your case you want 'count' to be a class attribute rather than a local variable. But yes, incrementing it each time that the method is called will serve your purpose.

Maybe you are looking for

  • How do I query ink level in Epson CX3650 with printer-gui

    Hi, When using the printer gui in KDE to query the ink level on my Epson Stylus CX3650 I get the following error message Cannot open /Stylus CX3600 read/write: No such file or directory But when I use the command line tool I get [rene@archer mtink]$

  • Aggregation rule ignored for Logical sources

    Hi, We are using materialized views as logical sources for our logical tables. These logical sources contain aggregated data at higher level for dimensions. However, we have a logical source at the most detailed level for the dimensions. Problem: We

  • Roundtrip issues [Lr5.3 to Ps cc]

    Hi everyone, in the past two days i experience an issue in Lr-Ps roundtrip.I use to do that work from Lr 4 to Ps6 in my old win7 machine with no problems. Resently move to mac OS X (mountain lion)platform and be a member in Adobe`s CC.I try as always

  • Create Delivery with reference to seasonal stock transport order

    Hello Gurus How do we create a delivery with respect to seasonal stock transport order, in R/3 4.7. Thanks in advance

  • Adobe Form - to fade oute a Form part

    Hello, what I have: A Adobe Form with Masterpage and page1 and page2. an interface with many variables. Two of them are the name for appraiser1 and appraiser2 Problem: If the field appraiser2 is empty, the second page shouldn't print. manual I have m