Overriding doPost() better than service() method

why overriding doPost() or doGet() is better than service() method
in servlets
thanx

One reason is to help break your code up into more manageable pieces. For example, let's say you have a page that displays a list of Employees when called via GET, but also includes a FORM that lets you delete employees based on checkboxes included on the form with a SUBMIT button. If you use the doService, you'll probably have to do something like this:
doService(request, response) {
  if (request.getMethod().equals("get")) {
    // handle GET logic
  else {
    //  handle POST logic
}However, if you have two separate methods, it makes the logic a little simpler. For example:
doGet(request, response) {
  // handle GET logic
doPost(request, response) {
  // handle POST logic
}The distinction is fairly minor, but I do think the code is cleaner without having to check for gets and posts. With that said, I have plenty of servlets that use the doService() method because there is no distinction in those servlets between the doGet() and doPost() functionality.
Michael

Similar Messages

  • How XI is better than BAPI method

    Dear all,
    How XI technology is better than BAPI method, with the help of BAPI we can connect Non SAP system with SAP then why XI is better and in what respect.
    Thanks,
    RP

    > Hi,
    > Can you connect BAPI with some DB system without XI?
    >
    > Cheers,
    > Jag
    Of course you can.
    Just develop a Java/.NET application that will call RFCs through JCo/.NET Connector and DB's through any driver you want.
    Regards,
    Henrique.

  • Disadvantages of Overriding service() method in servlets?

    Hi,
    Could you please tell me what are the possible disadvantages of overriding service() method in the servlets?

    If there is some business logic in the service() itself? without the control being transferred to doGet() nor doPost()?
    then what might be the disadvantages of overriding service()But there isn't any business logic in the service() method itself, unless you override it. You are going around in circles here. This is making no sense at all.

  • Can we have more than one service method in a single servlet

    can we have more than one service method in a single servlet?explain with example

    No, you can only have one service method. However, you can have it process two different requests as follows.
    Lets say you have two JSP pages. Put a hidden text value in one called jsp1 and a hiddent text value in the other called jsp2 (example: <input type="hidden" name="jspPage" value="jsp1"> and <input type="hidden" name="jspPage" value="jsp2">.
    Then in your service method, read in request.getParameter("jspPage") to determine if its jsp1 or jsp2 and call up the appropriate logic to process them separately.

  • HT4623 This really ***** that they sent out and update to the iPhone ISO6 and I can't send or receive pics! Being that its apple you would think they would know better than to send out a bad update like this! I'm paying for a service and I can even use it

    This really ***** that they sent out and update to the iPhone ISO6 and I can't send or receive pics! Being that its apple you would think they would know better than to send out a bad update like this! I'm paying for a service and I can even use now!!! I'm very upset! Think about canceling my iPhone 5 order! This is terrible!

    Wahhhhhhhhhh! Wahhhhhhhhhh!
    Are you over your little tantrum now?  Do you want help you would like to continue to act like a toddler?
    If you want help, try telling us what happens when trying to send pics.  Any errors?
    If you want to whine... go somewhere else.

  • Test-to-speech program--anything better than  Voice Dream Reader? I have AMD and NEED the serviced.

    I have AMD and need a text-to-speech reader; anythiung better than Voice Dream Reader? HELP!!

    My son uses Touch Chat. It wworks great for him.  he is 14 years old and has been using it for 2 years.  You can set up several different pages to ease navigations.

  • Why we need doGet() or doPost() instead of service()

    Though we have service() method in http servlet why we need to override the doGet() or doPost() of Httpservlets
    2services methods are availbale in HttpServlets
    1.protected void service( Httpservelt request hreq, HttpServletResponse hresp);
    2. Public void service( servletRequest req, servletResponse resp)
    Read this and tell how it is(it was collected from documentation of Jguru site)
    NOTE: the doGet() and doPost() methods (as well as other HttpServlet methods) are called by the service() method.

    The service() method from the Servlet interface is overloaded in HttpServlet to accept HttpServletRequest and HttpServletResponse. If you read the API documentation, you will note that it says the overloaded service() method will dispatch to doGet, doPost, doPut, etc. based on the type of request.
    This approach makes sense, because it is bad design to put all your code in one method, or one class for that matter. Usually the doGet/doPost/do<Whatever> methods are themselves dispatcher methods that call the proper classes/methods based on the logical contents of the request.
    This is in fact a common pattern in servlet frameworks like Struts and Spring. Said frameworks use a generic DispatcherServlet that redirects requests to the appropriate classes/beans as declared in the configuration files.

  • Rest Service method called twice in wcf

    Hi all,
    I have created a rest service using wcf.
    I am writing Entity framework code within a service method to fetch data from database.
    Every call from browser is hitting the service method twice or thrice.
    I found no exception within the method. I encountered same problem before and solved it adding DataContract attribute to all the models(not helping now).
    What may be the possible reasons? Please help.
    Regards
    Ashish

    Hi,
    I want to know if you are using the WebGet (Http GET). If so, please try to change that API to WebInvoke (Http POST).
    Because IIS has some setting for HTTP GET as 40sec replay, so if within 40sec the server does not get response, then it will query itself again. Then it will be called twice or more.
    For more information, please try to refer to:
    #RESTful API in WCF get called more than one time:
    http://www.codeproject.com/Tips/338142/RESTful-API-in-WCF-get-called-more-than-one-time-b .
    Best Regards,
    Amy Peng
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Can we override doGet() instead of service() ?

    Suppose that we didn't specify method in form
    <form action = "run" >
    </form>
    then in the servlet which method would we override ?
    Also i have a confusion that is it possible to override doGet() or doPost() method instead of service() method ?

    What do you mean by 'what?'
    What part of my answer didn't you understand?

  • Handling deletions from vo via service method - how?

    If you create a hyperlink to delete a row (from a grid), i.e.
        &lt;a href="MyPage.do?event=RemoveNew&Arg0=&lt;c:out value='${Row.rowKeyStr}' /&gt;"&gt;Remove&lt;/a&gt;
    What do you do with this Row Key String? I'm reluctant to use a value (such as a PK ID#) as I like the transparency of the key string, and wouldn't really want the user issuing a URL and just changing the pk value and removing something else.
    So, do I:
    a) pass this rowKeyString to the service method, which I can't see how I can even look up anything in an appmodule based on a rowkeystring, I really need a oracle.jbo.Key, but creating a Key from a string is deprecated
    public void onRemoveNew( DataActionContext ctx )
           log.info(userName(ctx) + "onRemoveNew **** - START");
           try
              // grab rowKeyStr from from end hyperlink (Arg0)       
              String strRowKey = ctx.getHttpServletRequest().getParameter("Arg0");      
              AppModule am = getAppModule(ctx);
              am.removeRowbyRowKeyStr( strRowKey );
           catch ( JboException jex )
             au.logException( jex, log );
             throw jex;
           log.info(userName(ctx) + "onRemoveNew **** - END");
        } // onRemoveNewthe backend service method "stub" for now:
    public void removeRowbyRowKeyStr( String rowKeyStr )
        log.info(userName(ctx) + "removeRowbyRowKeyStr**** - START");
        // Since no navigation took place on front end, first let's find this row
        // what do I do with this rowKeyString
        // deprecated:    Key k = new Key( rowKeyStr );
        ViewObject vo = findMyViewObject();
        try
             Key k = new Key ( rowKeyStr, vo.getKeyAttributeDefs() );
             // proceed from here...
        catch ( Exception ex )
              au.logException( ex, log );
        log.info(userName(ctx) + "removeRowbyRowKeyStr**** - END");
    } // removeRowbyRowKeyStrb) issue the setcurrentrow in the front-end to get to the correct grid row, grab the pk column# of this row, then call the service method
    c) something altogether different than these ideas that escapes me right now, but is the preferred/best practice
    Thanks!

    You can use JboUtil.getRowFromKey(RowSetIterator rsi, String skey) to do the job.
    You can pass any ViewObject, RowSet, or RowSetIterator to the first argument, and your string key to the second argument.
    Out of curiosity, it's source code looks like this:
       static public Row getRowFromKey(RowSetIterator rsi, String sKey)
          Key key;
          try
             key = new Key(sKey, rsi.getRowSet().getViewObject().getKeyAttributeDefs());
          catch (Exception ex)
             ex.printStackTrace();
             return null;
          Row rows[] = rsi.findByKey(key,1);
          if (rows.length <= 0)
             return null;
          return rows[0];
       }

  • IMovie capture quality better than anything FCP can offer for consumer DV?

    As a newbie to FCP, I have not found Capture, sequence, and export settings that is equal to or better than what iMovie 08 can create. Prior to this, I've been using iMovie 08 which is extremely user friendly. Just plug in the fire wire connections and it auto detects only one setting for DV. I am not sure what format it captures in but it does a good job. When I export out of iMovie 08 I use "using Quicktime" and choose the Uncompressed 8-bit NTSC method. The result is a decent, non-interlaced looking .mov file.
    The first time I tried to capture with FCP I chose the easy setup, where I would capture in the NTSC DV, sequence would be NTSC DV and export using the current settings in quicktime. The result was an interlaced and lowered quality vid.
    I have also tried the following combinations with no success with quality comparisons w/ iMovie 08:
    capt: NTSC dv, seq: NTSC DV, progressive exp: Uncompressed 8-bit
    capt: Uncompressed 8-bit, seq: Uncompressed 8-Bit exp: Uncompressed 8-bit
    This last one came close, but still iMovie 08 was better.
    My assumption is that FCP would contain the settings to duplicate or even out perform iMovie's export quality for consumer video dv. I viewed iMovie as little brother and FCP as big brother. Shouldn't FCP produce equal to or better quality than iMovie 08? And what are the settings for this?
    Thanks

    Thank you for clearing up my confusion. How is my export from iMovie 08, using "Uncompressed 8-bit" coming out progressive (I see no interlaced, odd/even scan lines)? Is this export dropping lines/information? If so, uncompressed is not an appropriate name for the export.
    I understand what you are saying about "getting quality back" on export. My initial question was comparing the quality of an iMovie 08 export vs. FCP export and having the problem of a lowered output from the FCP export.
    If anyone has the time, would they try a short experiment:
    1. From your DV source, camera or deck connect to your computer
    Capture a short clip via iMovie 08 a short clip in standard 4:3.
    Export using Quicktime, Uncompressed 8-bit setting
    2. From your DV source, camera or deck, connect to your computer.
    Capture the same short clip to FCP using Easy set up for NTSC DV. Export with current settings.
    3. Compare the two.

  • Service Method trouble

    I'm having trouble calling upon a service Class method (Convert.java)i've created which:
    1. Receives an Uppercase String
    2. Converts the Uppercase String to a lowercase String.
    3. Converts the now lowercase string into a single char.
    4. Returns the char back to Main.java
    Convert.java
        public class Convert {
        public static char con(String txt) {
        txt = txt.toLowerCase();
        char done = txt.charAt(0);
        return done;
    }how would I send data to this service class method from a different module?

    Are you asking how you'd invoke this method from a different class? You're using words with big connotations for what looks like a simple problem. It's not clear what you mean by "service method" other than just a static method, either.
    If you want to invoke the method, just put the class name in front of it:
    char c = Convert.con("Here is a string");Both the class and the method are public so you should have no trouble, unless you're using packages inconsistently.

  • Web Service Method that returns an ArrayList

    Hi guys,
    I have to create a web service method that returns an ArrayList, but it's not working. My problem is:
    With the "@XmlSeeAlso" annotation, my client prints the result, but the ArryaList is not from java.util, it's from org.me.calculator so I can't use it.
    If I remove this annotation, I get no result, with this error message on Tomcat 6:
    [javax.xml.bind.JAXBException: class java.util.ArrayList nor any of its super class is known to this context.]
    I'm a newbie, and trying to understand web services (I read some posts here, but didn't get the point, from its answers), but this problem I just can't figure out how to solve....
    WEb Service
    package org.me.calculator;
    import java.io.Serializable;
    import javax.jws.WebMethod;
    import javax.jws.WebParam;
    import javax.jws.WebService;
    import java.util.*;
    import java.util.ArrayList;
    import javax.xml.bind.annotation.XmlSeeAlso;
    * @author eduardo.domanski
    @WebService()
    @XmlSeeAlso({java.util.ArrayList.class}) // With this, I can see the result on client, but, the ArrayList is an org.me.calculator.ArrayList class.... Strange...
    public class CalculatorWS {
        @WebMethod(operationName = "valores")
        public ArrayList valores(@WebParam(name = "a") int a,
                           @WebParam(name = "b") int b) {
            ArrayList teste = new ArrayList();
            ArrayList a1 = new ArrayList();
            a1.add(a);
            a1.add(b);
            ArrayList a2 = new ArrayList();
            a2.add(a+b);
            a2.add(a-b);
            teste.add(a1);
            teste.add(a2);
            return  teste; 
    }CLient
    package org.me.calculator.client;
    import java.io.*;
    import java.net.*;
    import java.util.ArrayList;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class ClientServlet extends HttpServlet {
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet ClientServlet</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet ClientServlet at " + request.getContextPath() + "</h1>");
            try { // Call Web Service Operation
                org.me.calculator.CalculatorWSService service = new org.me.calculator.CalculatorWSService();
                org.me.calculator.CalculatorWS port = service.getCalculatorWSPort();
                // TODO initialize WS operation arguments here
                int i = 8;
                int j = -6;
                // TODO process result here
                ArrayList result = (ArrayList) port.valores(i, j);
                out.println("Result = " + result);
            } catch (Exception ex) {
                System.out.println(ex);
            // TODO handle custom exceptions here
            out.println("</body>");
            out.println("</html>");
            out.close();
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            processRequest(request, response);
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            processRequest(request, response);
    }THank you all,
    Eduardo
    Edited by: EduardoDomanski on Apr 23, 2008 4:40 AM

    I forgot to say that, when I try to return an ArrayList of an object, for example, ClassA, which is on the package org.me.classes, on my Server App, the ArrayList is returned, but the objects are from type org.me.calculator.ClassA. It should be from org.me.classes.ClassA, right?
    This package also exists on my client App, to use the object, but as the returned type is from another package, I can't even cast it. I tried some annotations @Xml... but it failed.
    Packages
    ServerApp
    org.me.calculator
    CalcWS.java
    org.me.classes
    ClassA.java
    Client App
    org.me.classes
    ClassA.java
    The return from my method should be an ArrayList of org.me.classes.ClassA, but when I print it, on client, it's from org.me.calculator.ClassA.
    Does anybody knows, or had the same problem?
    Thanks,
    Eduardo

  • Re: On 105 mbps plan but never get better than 22 mbps

    I am living in this SAME nightmare!  Help.  I spent ALL day yesterday 8 hours on the phone with many many different people, some who were just plain RUDE and others who all contradicted each other. Sent me to get a new modem and we did that, speed still like the above.Called today, got a decent guy he tried helping for a while then phone cut out.  No call back.UMMM really?  Then yesterday during Chat, they guy just shut me off.I have 105 per my preferred bundle.  Really want to get that.  SOOOO Angry, if they did NOT have MONOPOLY on my community I would switch.  I however have NO one to switch to.  SO unamerican.  Poor service, HIGH prices. I left service center in tears as I watched elderly couple hobble out on their canes wondering how they can pay the increase to their bill.  That is just NOT right.  

    X1DESMO wrote:
    I just got the same svc hooked up today and I too am only gettign mid 20's ?!?!?    Using my own modem Motoroal SB6121 ( certifed on the Comcast site to work with even the 150 speed tier.. And a Neggear N300 router ( capable of over 300MBs) and only mid 20's Seriously?...  I get 25 upload???    Go to my parent s place they have the Comcast provided Modem router combo unit ( also wireless N) and the 50 MB svc, I get a solid 62 over there witht the same laptop and ipad.   WHAT GIVES? The technition made a comment that has me very concerned.. " I have NEVER seen anyone with the Extreem 105 pkg get better than 50 over Wi Fi, even with the COmcat modem in the same roon."  This I will be looking into ove the next several days, as that is a totally unaccepable answer, we pay for 105 ALL of our equipment is rated to levels ABOVE 105 and we cant get HALF of that... Soory Comcast this wont fly, if that is in fact "just how it is"   I see a class action suit coming there way for sure as its blantant fals advertising.  If/and/or when I get it solved i will be sure to post up here..Try this: http://forums.comcast.com/t5/Basic-Internet-Connectivity-And/Connection-Troubleshooting-Tips/td-p/1253575

  • Whether installing 64bit OS is better than 32bit in a 64 bit PC?

    Hallo friends,
    Now a days 64bit PCs are more common. But I think Operating systems and programs have not attained  capacity to fully exploit the power of 64bit machines. (Of course Linux is better than MS counterparts in 64bit zone). If it is sensible to stick with 32bit for better experience in terms of stability and performance? What are the pros and cons of both methods? How we can attain maximum from 64bit PC?   Since every one with a 64bit PC have tried both architectures, feed back opinions and suggestions in the above thread is anticipated from everyone.
    Thanks to all
    mvdvarrier

    I've made some tests with current Arch i686 and x86_64 on a old AMD Turion 64ML-30
    MD5 Bruteforce attack:
    i686: 43,5s
    x86_64: 31,2s
    import md5
    import sys
    haslo = 'kogut'
    hasz_hasla = md5.new(haslo).hexdigest()
    def make_word(m, base_string=False):
    znaki = 'qwertyuiopasdfghjklzxcvbnm'
    for i in znaki:
    if base_string:
    string = base_string + i
    else:
    string = i
    if md5.new(string).hexdigest() == m:
    print 'Podane Haslo to: ' + string
    sys.exit()
    elif len(string) < 5:
    make_word(m=m, base_string=string)
    make_word(hasz_hasla)
    Untar Gentoo stage3 to /dev/null:
    i686: 48,3s
    x86_64: 42,3s
    Make a thumb out of 3,1MB jpeg file with convert:
    i686: 1,62s
    x86_64: 1,28s
    Make avi from Big Buck Bunny with ffmpeg:
    (ffmpeg -i big_buck_bunny_480p_stereo.ogg a.avi) making mpeg didn't work on i686 - segmentation fault
    i686: 276s
    x86_64: 295s
    Make mpeg from Big Buck Bunny with mencoder:
    (mencoder big_buck_bunny_480p_stereo.ogg -oac lavc -ovc lavc -o a.mpeg)
    i686: 263s
    x86_64: 251s
    Last edited by Riklaunim (2008-10-18 21:04:28)

Maybe you are looking for

  • How do I transfer information from one ipod to another?

    I would like to transfer the music, etc, from one of my daughter's ipod touches, to another daughter's ipod touch, as well as pix, etc.

  • How do i get my photos back from icloud

    HELP!!! I think this maye be of no use but.. I brought a new iphone on the weekend in sydney and I started using it right away and click on use icloud. I took many photos over the weekend and when I got home (sleep deprived) i plugged it into my lapt

  • Upgrade to mac osx10.8.4

    Puedo revertir el upgrade q le hice a mi mac Lion a mac osx 10.8.4 y si lo hago mi batería vuelve a la normalidad ahora no dura nada?

  • Wbs element can no longer be shifted error while creating wbs

    i am trying to create wbs with bapi_project_maintain, i am facing an error with message no 418 WBS element 1899-CAP-10-100-001-1507 can no longer be shifted

  • Moving objects through all keyframes

    hello all, i want to make chages in my website and i have a problem: im trying to move objects, but i dont want to have to do the change in all my keyframes... how do i make position changes that effect all of the keyframes? with thanks, joel www.joe