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.

Similar Messages

  • Applications are mentioned free, but when we start downloading one dollar is charged in my credit card, but only for the first time when i switch on and use it for the first time one dollar is charged. and from next application it is free. why?

    Applications are mentioned free, but when we start downloading one dollar is charged in my credit card, but only for the first time when i switch on and use it for the first time one dollar is charged. and from next application it is free. why?

    Kindly inform any email id or toll free number to contact apple for your below answer, Mr.King_Penguin
    About receiving my credit card being debited for Free App Store Application downloads,
    It should be within a few days, but it might vary a bit by bank/provider :
    I am in India, if the bank don't refunds , what to do?
    Rajagopal.pngr :-  It is only a holding charge, it is not a permanent charge. If it isn't refunded within a few days or so (and it quite possibly won't be over a weekend) then you can query the charge with Apple.

  • Is it normal that every time when I switch off my Iphone 5s and then I turn it on again I have to insert my pin code?

    Is it normal that every time when I switch off my Iphone 5s and then I turn it on again I have to insert my pin code?

    That's what I was suspecting they were asking , but wanted to make sure.

  • My iphone5,ios7.1.2...itunes. Version 11.3.1.2 ...when ever i connect ..on iphone from my windows computer on iphone screen it shows that "THIS ACCESSORY MAY NOT BE SUPPORTED " .....every time when i connect this pop up used to appear on

    my iphone5,ios7.1.2...itunes. Version 11.3.1.2 ...when ever i connect ..my iphone from my windows computer ....on iphone screen it shows a kind of pop up "THIS ACCESSORY MAY NOT BE SUPPORTED " .....every time when i connect this pop up used to appear on...kindly resolve my isshue

    iOS 7 will give errors on non Apple certified peripherals.  So make sure you only use Apple certified products. Did you backup the phone and then RESTORE AS NEW (not reset)? Try doing that by plugging the phone to iTunes on a computer. See if that helps. If it solves the problem, there could have been corrupted software on you phone. If not, it could be a hardware issue (including the battery), in which case you would need to go to a Apple Store or authorized service provider.
    Use iTunes to restore your iOS device to factory settings - Apple Support

  • I want to be able to use 2 different scanner machines (A4 and A3). I have installed the 2 drivers. When I switch usb cables to use the other scanner in I get the message saying there is no scanner installed. I can see the 2 machines in the printer list.

    I want to be able to use 2 different scanner machines (A4 and A3). I have installed the 2 drivers.
    However it seems I can only use only 1 scanner.
    Because when I switch usb cables to use the other scanner and try to import in Photoshop ,I get the message saying there is no scanner installed.
    I can see the 2 machines in the printer list.

    I want to be able to use 2 different scanner machines (A4 and A3). I have installed the 2 drivers.
    However it seems I can only use only 1 scanner.
    Because when I switch usb cables to use the other scanner and try to import in Photoshop ,I get the message saying there is no scanner installed.
    I can see the 2 machines in the printer list.

  • Can I test (junit) default case of switch-case statement ?

    Hi,
    I have a class which has switch-case statements and I am trying to junit test with 100% coverage. My switch-case workes based on enum values.
    say my enum values are 1, 2.
    switch(getEnumValues) {
    case 1:
    return "some value";
    case 2:
    return "some value";
    default:
    throw new UnsupportedOperationException("No such enum value supported.");
    I have test case to test the case 1 and 2 but I am not able to test default case. Can anyone please let me know how can I right a junit test case for default case.
    Edited by: TUIJAVADEV on Nov 4, 2008 4:15 PM

    yawmark wrote:
    TUIJAVADEV wrote:
    I have test case to test the case 1 and 2 but I am not able to test default case. Can anyone please let me know how can I right a junit test case for default case.If your enum values are ONE and TWO, and you have cases for both, then there is no "default case". There is nothing to test.
    ~If I'm reading the OP correctly, they're 1 and 2, not ONE and TWO. That is, not values of a Java enum.
    If this is the case, then the easiest way to test the default case is to break the swtich out into a separate, package-accessible method that takes and arg and passes that onto the switch. (There may be variations on this, depending on how your code is structured.)
    However, in a similar vein to what the others are saying, if you already know that you'll only ever have 1 and 2 by the time you get to the switch (maybe because the value comes from an argument to the enclosing method, and you've already unit tested that it appropriately throws an IllegalArgumentException when other values are passed, then there's no need to test the default.
    Finally, though if it is ints 1 and 2, rather than a true enum, why not switch to an enum?

  • Help with Switch-Case Statement

    How do you get this in a switch-case statement or work with it?
              if (age < 70) {
                        JOptionPane.showMessageDialog(null, "People that are below the 70s are nothing special.");
              else if (age > 69 && age < 80) {
                        JOptionPane.showMessageDialog(null,  "People that are in their 70s are called septuagenarian.");
              else if (age > 79 && age < 90) {
                        JOptionPane.showMessageDialog(null,  "People that are in their 80s are called octogenarian.");
              else if (age > 89 && age < 100) {
                        JOptionPane.showMessageDialog(null,  "People that are in their 90s are called nonagenarian.");
              else (age > 99 && age < 110) {
                        JOptionPane.showMessageDialog(null,  "People that are in their 100s are called centenarian.");
                   }Thanks~

    As per Java Specification, swtich case expects an integer and boolean cannot be used as param for switch.
    In your case switch can be used like this.
    int index = age /10;
    switch(index) {
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    Your First case
    break;
    case 7:
    your second case
    break;
    case 8:
    third case
    break;
    case 9:
    fourth case
    break;
    default:
    fifth case
    break;
    Take note of the break statements. Its very important. But I wont prefer in this case. Code looks awkward and is not so meaningful.....

  • I would like to have only 1 Tab close at a time instead of 2 each time when I have multiple links in use.

    I have gone to about:config to browser.tabs.close buttons. They allow digits of 0 thru 3. I have tried all the numbers.
    0 shuts down 3 or more tabs at once, and 1,2, 3 all close two tabs at a time.
    How do I change back to 1 tab being closed at a time?

    hello, the preference you have mentioned doesn't control how many tabs are closed at one time - it should always be only one tab at a time when you click on the close button. if this isn't working as intended, you could try to replicate this behaviour when you launch firefox in safe mode once. if it is not happening there, maybe an addon is interfering ...
    [[Troubleshoot extensions, themes and hardware acceleration issues to solve common Firefox problems]]
    otherwise it might be a problem with your hardware - test it with a different mouse.

  • Switch Case Statement Help...

    Hello,
    I am trying to get my pages through Case Statement But...
    Can any one Help me.. here is my code..
    This is my Buttons Code... My buttons are on 1st Frame of My FLA..
    stop();
    btn1.addEventListener(MouseEvent.CLICK, varTest);
    btn2.addEventListener(MouseEvent.CLICK, varTest2);
    function varTest(event:MouseEvent):void
         var page = 1;
         gotoAndStop(20);
    function varTest2(event:MouseEvent):void
         var page = 2;
         gotoAndStop(20);
    and this is my 20th frame code. (here I'm checking variable)
    import flash.events.Event;
    addEventListener(Event.ENTER_FRAME,checkCaseMe);
    function checkCaseMe(event:Event)
         switch (page)
              case "1" :
                   info_txt.text = "page1";
                   break;
              case "2" :
                   info_txt.text = "page1";
                   break;
              default :
                   info_txt.text = "page00";
    When I test the movie.. Error Occured (Scene 1, Layer 'Actions', Frame 21, Line 6 1120: Access of undefined property page. )
    Can Anyone help please.. How do I correct this....???
    Thanks...

    You should learn to use the trace() function to help you troubleshoot code yourself.  In each of your button functions include:
    trace("btn clicked"); // will help you know for sure that the buttons are working
    And in frame 20, you should add a trace as well to determine whether you actually get there when you think you don't...
    trace("in frame 20");
    Lastly, your code for frame 20 is likely not what you need for a couple of reasons...
    1) If you think the ENTER_FRAME listener is used to detect/trigger when the timeline enters a frame, that is not what it does.  What it does is continually process the function that it calls at the frame rate of the file.  It is normally only used when you want to repeatedly trigger some functionality.
    2)  If you assign number values to the page variable, you do not want to use String values in your cases.
    All you should need in frame 20 is...
    switch (page)
         case 1 :
              info_txt.text = "page1";
              break;
         case 2 :
              info_txt.text = "page1";
              break;
         default :
              info_txt.text = "page00";

  • WDDOINIT method executes every time when returning to View

    We are making Enhancements to the Travel Expense WDA. (Package: PTRM_WEB_UI)
    When creating a New Expense Report, the WDDOINIT method is being executed only once each time the View is displayed.  This is what is expected.
    When changing an existing Expense Report, the WDDOINIT method is being executed each time the view is displayed.
    The Lifetime Property of all of the views are set to "framework controlled".  It seems like when in change mode, the lifetime property of the views is acting as if they were set to "when visible". 
    Is there some way that this property is being dynamically changed when in change mode?  Does anyone know if SAP intended the Travel Expense WDA to act this way when in change mode?
    Any help or insight regarding this issue would be helpful. 
    Thanks,
    Aaron

    It could be that there are multiple component usages and that this view belongs to an inner component. The parent component could call DELTE_COMPONENT on the component usage if no views from that componet are currently visibile.  This is done for memory manage as there is no garbage collection of compoonent instances at runtime. This would have the effect that the WDDOINIT would be called again if the component is used again/the view is reshown. I have seen complex internal applications that use separate components for each tab for instance.  When the tab switch occurs, they perform a DELTEE_COMPONENT.  This can have a significant positive impact on the memory consumption of the session. This could explain the behaviour you are seeing.

  • B1 Query returning truncated decimal places when the CASE statement is used

    Hi All,
    Perhaps this is a friday thing.
    In B1 the price setting is for 5 decimal places. I have a query the run a business process looking at the data in the Special Prices Tables. When I run the Query in SQL, the output show the correct number of decimal places. However, when the Query is then  saved and run in B1, the output is truncated to 2 decimal places. Any ideas as to how I can prevent this for happening?
    T0: Points to teh OSPP Table
    T1: Points to the OSP1 Table
    The portion of the query causing the issue is as follows:
    case
       when (T1.price is not null) then
             T1.price
       else
           T0.price
    end

    Hi Earl
    Seems you are right, I have tested with a few different formats and each time get a 2 decimal result. In SQL help I found the following which may explain why:
    Result Types
    Returns the highest precedence type from the set of types in result_expressions and the optional else_result_expression. For more information, see Data Type Precedence (Transact-SQL).
    Even tried it in SQL with a stored procedure storing to a temp table and it shows the full decimals, but executing the SP in SAP Business One results in 2 decimals again.
    This is indeed a strange occurrence and I a not sure how you are going to solve it! You can use NVARCHAR for example except that it right aligns the values returned, but at least it doesn't drop the decimals.
    Kind regards
    Peter Juby

  • Regading WHEN usage in CASE statement

    Hi All,
    I have a issue with <b>WHEN</b> in <b>CASE</b> statement.
    The actual issue is i have one statement is program[<b>REP1</b>] as below:
    <b>DELETE S012.</b>
    Now i am using the <b>REP1</b> in my new program by copying all the commands in <b>REP1</b> into one Internaltable <b>I_TAB</b>.
    In this <b>I_TAB</b> internal table i have a field <b>COMMANDS</b> which is filled as below for above code:
    <b>DELETE
    S012
    .</b>
    Now When i am using following code in <b>REP2</b>.
    <b>CASE I_TAB-COMMANDS.
      WHEN 'DELETE'.
    Some Updation Code
      WHEN 'INSERT'.
    Some Updation Code
      WHEN 'UPDATE'.
    Some Updation Code
      WHEN 'X'.
    Some Updation Code
      WHEN OTHERS.
    Some Updation Code
    ENDCASE.</b>
    It is not going inside <b>DELETE</b> though it is there in <b>I_TAB</b> Internal table.
    Same is the case with <b>INSERT&UPDATE</b>.
    Can anybody tell me why it is not going inside of <b>WHEN 'DELETE'</b>
    Can anybody solve this issue!
    Thanks in advance.
    Thanks,
    Dep.

    Put the Itab in a loop. so that every time loop passes the ITAB-COMMAND will have the value for that field related to that loop pass. 
    Inside loop , if you put your case stmt , it will execute the case for all the ITAB-COMMANDS.
    like....
    loop at itab.
    CASE I_TAB-COMMANDS.
    WHEN 'DELETE'.
    Some Updation Code
    WHEN 'INSERT'.
    Some Updation Code
    WHEN 'UPDATE'.
    Some Updation Code
    WHEN 'X'.
    Some Updation Code
    WHEN OTHERS.
    Some Updation Code
    ENDCASE.
    endloop.

  • Need help about switch & case statements

    Dear friends
    I am new student of Java
    Our University gave us project to make a program. Here is the program:
    a- Write a java program ,so the user can input the monthly salary then compute the net salary of an employee after deducting the tax ,use the following table to calculate the tax .Note use switch statement .
    Annual salary Tax
    100- 999 0
    1000- 1999 5%
    2000- 3999 7%
    4000- 7000 10%
    7000 13%Please help me how could I use switch statement.
    All I know about switch statement is that I have use Integers for selection.
    Kindly help me. I have only 2 days to submit my assignment.
    Thanks in Advance
    Edited by: syedejaz on Aug 13, 2008 8:09 AM
    Edited by: syedejaz on Aug 13, 2008 8:10 AM

    Hello every body:
    I tried to make my first program using if then else but the problem is that no calcuation is happinig
    /*  TMA01 ITC250, Part-III, a
      Program which gets input monthly salary and shows net salary after deducting given tax.
    File: netSalary.java
    import javax.swing.*;
    import java.text.*;
    public class netSalary {
    public static void main(String[] args) {
           int Salary=0,Tax=0,monthlySalary=0;
           monthlySalary= Integer.parseInt(JOptionPane.showInputDialog(null, "Enter Monthly Salary:"));
           if ((monthlySalary>=100) && (monthlySalary<=999)) {
                Tax = (monthlySalary*(0/100));
          Salary = (monthlySalary-Tax);
         JOptionPane.showMessageDialog(null, "Net Salary is:" +Salary);
            } else if ((monthlySalary>=1000) && (monthlySalary<=1999)) {
                Tax = (monthlySalary*(5/100));
         Salary = (monthlySalary-Tax);
         JOptionPane.showMessageDialog(null, "Net Salary is:" +Salary);
            } else if (monthlySalary>=2000 && monthlySalary<=3999) {
                Tax = (monthlySalary*(7/100));
         Salary = (monthlySalary-Tax);
         JOptionPane.showMessageDialog(null, "Net Salary is:" +Salary);
            } else if (monthlySalary>=4000 && monthlySalary<=7000) {
                Tax = (monthlySalary*(10/100));
         Salary = (monthlySalary-Tax);
         JOptionPane.showMessageDialog(null, "Net Salary is:" +Salary);
            } else {
                Tax = (monthlySalary*(13/100));
         Salary = (monthlySalary-Tax);
         JOptionPane.showMessageDialog(null, "Net Salary is:" +Salary);
    } The tax is not detuting. please tell me the mistake
    Edited by: syedejaz on Aug 13, 2008 2:49 PM

  • HP laserjet 100 color MFP M175a printer driver to be installed evry time when the printer is made on

    Hello,
    I am having the above mentioned printer. The problem with this printer is every time when I switch-on the printer its driver has to be installed then only I can start printing. The following is my PC configuration:
    MB: ConRoe865GV chipset, CPU: PIV, OS: XP-SP3.
    Could you tell me what can the problem.
    Also if by mistake the paper in the paper-tray gets finished the printer takes quite a long time to detect that new paper bunch is there in printer. Is there a way to minimise this paper checking process.
    Kindly awaiting your fast reply

    Hi @RajBob ,
    I see that you are experiencing a issue with the printer installing every time you turn it on, then you are able to print again. Also when the paper runs out, it takes a long time to detect the paper in the tray again. I would like to help you out today.
    The printer has a Smart Install built into the firmware. Disable the Smart Install Feature to see if that will resolve the issue of the computer detecting the printer every time it is turned on.
    Go to Setup, Service Menu, Smart Install and turn it off please.
    If you are not able to print after turning the printer back on again, download and run the Print and Scan Doctor. It will diagnose the issue and might automatically resolve it. Find and fix common printer problems using HP diagnostic tools for Windows?
    For the paper not being detected right away, make sure the printer is connected directly to a wall outlet and try to keep the tray filled at all times, but not over filled.
    What were the results when you ran the Print and Scan Doctor? (did it print or scan, any error messages)
    What operating system are you using? How to Find the Windows Edition and Version on Your Computer.
    If you need further assistance, just let me know.
    Have a great weekend!
    Thank You.
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" on the right to say “Thanks” for helping!
    Gemini02
    I work on behalf of HP

  • What method is called only once in the life cycle?

    Hello,
    What method is called only once in the life cycle of an Entity Bean and Session Bean?
    Is it ejbRemove()?
    Thanks

    hi,
    ejbCreate() and setSessionContext() are called once by the container after the bean instace is created.when the bean instance goes to pool and again return to ready state to handle client requests these methods r never called .only bussiness methods r called.this is in case of stateless session bean.
    in case of stateful session bean, each bean instance is associated with client.so,when new client requests, new bean instance is created and above 2 methods are called. no pool terminology in case of stateful session bean.
    ejbRemove() is called by the container when it is abt to remove bean instance,so it its obvious tht it is called only once.

Maybe you are looking for

  • Why can I not manage online storage for Elements 9

    I purchased a Bamboo Create and I have had nothing but, problems with the Adobe software that came in it.  The other software works fine.  However, Adobe thinks I should upgrade immeditaely even though I just spent $200 to the new Elements.  In fact

  • Transaction type called by ITS - Transaction Launcher

    Hello guys, In the ICWC in CRM 5.0 what transaction type could we call with ITS by Transaction Launcher? For example, I know that we can call transaction like ppoma_crm, bp, is01, but if we defined Z transaction type in the path SPRO » CRM » Transact

  • Need material on Java Internals

    Hi, I need to learn how the JVM works and how a java program is executed in a JVM. Can anyone provide me reading material on this topic. Thanks

  • Encryption program does not work in IBM JDK

    Hi I have a encrypt, decrypt program, which does not work in IBM JDK the code is as below, it gives PBEWithMD5AndDES does not exist kind of error when running with IBM JDK import java.io.UnsupportedEncodingException; import java.security.spec.Algorit

  • WIFI is connected but says no service

    WiFi  is connected but says no service