Is it possible to write a doPost() method inside a doGet() method??

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class check extends HttpServlet
     protected void doGet ( HttpServletRequest rq, HttpServletResponse rp ) throws ServletException, IOException
          protected void doPost ( HttpServletRequest rq, HttpServletResponse rp ) throws ServletException, IOException
}I tried the above code and failed. So, if someone could answer me, I'd be really grateful!
Thanx in advance.

I tried the above code and failed. So, if someone could answer me, I'd be really grateful!
Thanx in advance.This code is simply illegal Java code. It has nothing to do with "doPost()" or "doGet()". Go back to school/books and carefully learn Java.
If you want to write logic for GET requests, implement doGet(). If you want to write logic for POST requests, implement doPost(). Otherwise just leave it away. If you want GET and POST requests behave both the same (I have never had such an odd requirement, but that's another story .. you're the developer here), then just let them call both the same method. Add private void doSomething(req, res) and let the doGet() and doPost() call it. Simple, isn't it?

Similar Messages

  • Is possible to write a custom tag inside another custom tag ??

    Hi
    I�m trying to reduce the time needed to code mi app presentation layer, it uses some custom tags with certain configuration, i would like to know if its possible to do something like this inside my custom tag doAfterBody().
    public int doAfterBody() throws JspException {
              JspWriter writer=bodyContent.getEnclosingWriter();
              try {
                   writer.print("<customTag:myAnotherTag someEspecificConfigurationParams="someEspecificValues"/>");
              } catch (IOException e) {
                   pageContext.getServletContext().log("Error: "+e.getMessage());
              }return SKIP_BODY;
         }The goal is to simplify the jsp code because the configuration params for the custom tags (css styles and similar) are allways the same.
    That don�t work, it simply prints <customTag:myAnotherTag/> in screen but the tag is not evaluated, i�ve tried too something like
    public int doAfterBody() throws JspException {
              if (repeat) {
                   JspWriter writer = bodyContent.getEnclosingWriter();
                   try {
                        writer.print("<customTag:myAnotherTag/>");
                   } catch (IOException e) {
                        pageContext.getServletContext().log("Error: " + e.getMessage());
                   repeat = false;
                   return EVAL_BODY_AGAIN;
              return SKIP_BODY;
         }And it doesn�t worked worked. Maybe using the taghandler classes and calls to the doAfterBody could make it work, but when you need to nest tags it could be a little hell of coupling calls, so before doing it i would like to know if what i want is possible. After reading some books i tought it could work because the stack of out objects, but i can�t make it work.
    Another idea is to inherit from tagHandler and override some properties in the tags, but i don�t like the idea to much.
    So, can anyone help me??
    Thanks.

    You cannot do that and I have listed out the reason and a possible solution in this post http://forum.java.sun.com/thread.jspa?threadID=697243 from yesterday.
    cheers,
    ram.

  • Write a servlet without doGet() and doPost() methods

    Hi,
    Can we write a servlet without doGet() and doPost() methods ?

    public class MyCoolServlet extends HttpServlet
    public void init(ServletConfig servletConfig) throws ServletException
    public void service(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException
    // your code here
    }Just an example on how to do it.
    A servlet is loaded by server (before any request). It will run the init function. Then pick up an request, spawn a thread and put this servlet code into the thread, give it session, request and response objects, then call serivce.
    Remember that init is called before, outside the thread, while service is inside the thread and the last to be called. Nice place to put your code.
    If you need to have some sort of init function to be called first on every request PR USER, then make your own function, and call it first in service method.
    Stuff that are put in init() function might only get runned once in the entire server lifetime. Until restart.

  • DoGet() & doPost() methods in servlets

    If we have method=�Get� in <form> tag and the servlet is having only the doPost() method then how the servlet handles the request? Is it possible or not?
    If we have method=�Post� in <form> tag and the servlet is having only the doGet() method then how the servlet handles the request? Is it possible or not?

    Usually business logic for get and post requests is the same, so this managed with additional process method called from doGet() and doPost().
    Something like
    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {...}
    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);
        }

  • Servlet doPost() method and "HTTP Status 404 - /HelloPost" error

    hi all
    i've a problem with doPost(...) method. i use Tomcat4.1 version and in root folder i store Form.html where i use a doGet() method and in WEB-INI>>classes i store Hello.class file for doGet() method. it works normally. but when i write a Form1.html for doPost() method with "<FORM METHOD=POST ACTION="/HelloPost">" line and store as same folder as Form.html and HelloPost.class in WEB-INI>>classes folder. its not working and showing a error
    "HTTP Status 404 - /HelloPost"
    error type =Status error.
    message=/HelloPost
    description =The requested resource (/HelloPost) is not available
    if anyone of u know what the problem is.. then plz inform me... it will help me a lot to learn servlet.
    thnx a lot
    Arif

    Your post is very hard to read. The next time try to be more accurate.
    i store Form.html where i use a doGet() method That makes no sense.
    I think you have a form with method="GET"
    and in WEB-INI>>classes i store Hello.class file for doGet() method. you have a Servlet called Hello which handles doGet(Request, Response) calls and whose class file you've put into WEB-INF/classes
    but when i write a Form1.html for doPost() method with "<FORM METHOD=POST ACTION="/HelloPost">" line and store as same folder as Form.html and HelloPost.class in WEB-INI>>classes folderIt's not enough to put a class file which has the same name as the action of your form into the folder WEB-INF/classes. The class must implement the (Http)Servlet Interface and you have to configure the servlet in the web.xml file.
    From where did you get the working Hello example code ?
    Look at the Chapter 11: Java Servlet Technology of the J2EE 1.4 Tutorial to learn how to write Servlets.

  • Jave servlets- doget() and dopost() methods.

    Iam trying to learn servlets but got confused on these doget() and dopost() methods usage. I just want to know generally what does these methods do in general (like the doget() sets the header..but what about dopost()?). I saw some example code where doget() is called within a dopost()method so Iam not clear about their purposes.
    I'd appreciate any help possible. Thank you.

    The doPost() and doGet() (also doHead() etc.) methods are all designed to handle specific HTTP request types. eg: doGet() handles HTTP GET requests (requests caused by common HTML links or typing a URL in your browser's address bar) while POST handles HTTP POST requests (commonly generated by HTML form submissions).
    When you see an example of a serlvet's doGet() being called within it's doPost(), it is because, at least for part of the processing, the servlet will be treating the two request types the same way.

  • Possible to write a function that takes any type as parameter ?

    I need to write a function that will take 2 parameters ( of any type - VARCHAR etc ) and return a boolean.
    ( Im trying to write a function that will do NULL processing.
    something like..
    if ( P1=P2 OR ( P1 IS NULL AND P2 IS NULL ) ) then
    return true ;
    end if;
    return false ;
    the function simply compares its parameters P1 & P2 and returns true if they are equal - including if both are NULL
    Is this possible to write at all.
    My code looks very ugly without this being wrapped in a function.

    You may be able to use SYS.AnyData for this. However, dealing with the data would be confusing, so overloading the FUNCTION would most likely be a better idea.
    This doesn't work, but it looked like fun, so i tried:
    CREATE OR REPLACE FUNCTION Equal_Or_NULL(A SYS.AnyData, B SYS.AnyData)
    RETURN PLS_INTEGER
    AS
    Local_A     VARCHAR2(4000);
    Local_B     VARCHAR2(4000);
    Junk          PLS_INTEGER;
    BEGIN
    IF A IS NULL AND B IS NULL THEN RETURN 1; END IF;
    CASE A.GetTypeName
      WHEN 'SYS.NUMBER'     THEN Junk := A.GetNumber(Local_A); Junk := B.GetNumber(Local_B);
      WHEN 'SYS.DATE'     THEN Junk := A.GetDate(Local_A); Junk := B.GetDate(Local_B);
      WHEN 'SYS.CHAR'     THEN Junk := A.GetCHAR(Local_A); Junk := B.GetCHAR(Local_B);
      WHEN 'SYS.VARCHAR'     THEN Junk := A.GetVARCHAR(Local_A); Junk := B.GetVARCHAR(Local_B);
      WHEN 'SYS.VARCHAR2'     THEN Junk := A.GetVARCHAR2(Local_A); Junk := B.GetVARCHAR2(Local_B);
    END CASE;
    RETURN CASE WHEN Local_A = Local_B THEN 1 ELSE 0 END;
    END Equal_Or_NULL;
    /Overloading would be much simpler, as the arguments could be directly compared.
    IMO, Do not do this. Hiding logic in a FUNCTION it for cosmetic purposes is a bad idea.

  • After download itunes installation began in windowx xp near the end of the installation the message says: it was not possible to write the value to the key Software / Classes / .mpg / OpenWithList / iTunes / .exe. Already reinstalled 3 times and always sa

    After download itunes installation began in windowx xp near the end of the installation the message says: it was not possible to write the value to the key Software / Classes / .mpg / OpenWithList / iTunes / .exe.
    Already reinstalled 3 times and always says the same message.
    thank you

    Only two had virus on windows XP this week and wiped them with Avast. The itunes asked me to install the update, and so I did. but it always gives me that message.

  • Is it possible to call a class method using pattern in ABAP editor.

    Hi,
         Is it possible to call a class method using pattern in ABAP editor.
    Thank U for Ur time.
    Cheers,
    Sam

    Yes,
    Click patterns.
    Then choose Abap objects patterns.
    Click on the Tick
    It will give a new screen
    Here Give the name of the class first.
    Then the object (instance of the calss)
    And finally the method ..
    it will give you the pattern
    Hope this helps.

  • IS IT POSSIBLE TO  WRITE ORDER BY CLAUSE WITHIN INNER QUERY

    IS IT POSSIBLE TO WRITE ORDER BY CLAUSE WITHIN INNER QUERY

    So you still can't :) I still don't see it that strict:
    You know of course that this is possible:
    select ename, (select ename
                     from (select   empno, ename
                               from emp
                              where deptno = 10
                           order by 1) e2
                    where e.empno = e2.empno) a
      from emp eso we have an »ORDER BY CLAUSE WITHIN INNER QUERY« which is even correlated (though through the outer query).
    Whether this makes sense or not is not question imho :-) ... but you can

  • You know guys if it's possible to write my name in my IpadMini once I already bought it? I mean, in the shop?

    You know guys if it's possible to write my name in my IpadMini once I already bought it? I mean, in the shop?

    If you mean you wish the iPad engraved, Apple will not do engraving after purchase. You will have to take the iPad to an engraving shop. Having it engraved may reduce the resale value, and since most people keep their iPad in a case or skin you may never see the engraving, and should the iPad ever need servicing by Apple it will probably just be replaced which would of course lose the engraving, so you should really think about whether you really want your iPad engraved.
    Regards.

  • AJAX calling a servlet's synchronized doPost method

    Hi all. This problem has been bugging me for a week already and still no solution in sight...
    Anyway, buttons in a page I'm creating uses AJAX to call a servlet's synchronized doPost method. Once a button is clicked, the servlet calls another java class which does some back end processing. Once the called java program is finished running, the page is updated telling the user that the selected backend process has finished running. It works fine if I just run one backend process at a time...however, if try to run another backend process while the previous backend process is still running, even if the backend process is finished, the page doesn't get updated with the message informing the user that the job is finished. The page only gets updated once all the jobs have finished running. What I want to happen is that whenever a job gets finished, the page gets updated.

    Yeah, it has
    something to do with the threads. However, I had to
    synchronize the doPost method because if the doPost
    method isn't synchronized, running 2 or more back end
    processes simultaneously would result in the previous
    backend processes being terminated, only the last
    back end process would be run successfully.Yea! that's what I wanted to say! most of the time there are critical sections in your code when concurrency is there, you need to recognize them and synchronize only the critical sections.
    I don't think synchronizing the whole dopost method is a better way to deal with concurrency issues. It defeats the purpose of spawning a new thread for each request(it's my personal opinion, I may be wrong).
    But I got one contradiction from one member of sun forum, he says spawning thread from a servlet is not a good practice according to java EE specification. But I don't think there is any way out other than this, to deal with this scenario. I am waiting for further suggestions, so keep an eye on this thread:
    http://forum.java.sun.com/thread.jspa?threadID=5149048
    ~cheers~

  • Possible to write non HTTP WEB services with an Application Server?

    Is it possible to write services with the backend of an application server in JavaEE 5? Like a server listening for mails? Where does one find information about that? Books only discuss web (html/http) services that you can build in an AS...

    Hi Dugu,
    Can you give the link to the specific article and the version of JDeveloper you are using to help you further?
    One thing to keep in mind is that the accessors must be public - using package access (no modifier) is not going to work.
    Hope this helps,
    Eric

  • Is it possible to write an abap code be SAP SQL query.(ECC 6)

    hello guys,
    Is it possible to write an abap code be SAP SQL query.
    Scenario : table A has a field say f1 of length 10 and table B has a field say s1 of lenght 20. in sap sql i am able to link all the other tables but i am not able to link
    table Af1 --->Table Bs1. as the length doesnot match. so is it possibel that using abap code I can pick 10 characters from table A field f1 adjust it to 20 characters using abap and map it to field s1 of table B.
    Please let me know how to accomplish this if possible.
    thanks in advance!!

    Herm,
    Adding code is done in the infoset.
    Please do following:
    > Goto SQ02
    > Type in the infoset that the basis for your query, <change>
    > Press <code> OR <shift><f8>
    > Tou'll see 4 tabs: Extras, Selections, Code, Enhancements.
    > GoTo tab Code
    > Choose the coding section (<f4> gives you an overview)
    > Enter the code.
    You may set a breakpoint to see what the query in SQ01 will do with it.
    Succes!
    Frank

  • Is it possible to write a Java program to turn off the computer

    Is it possible to write a Java program to turn off the computer

    import java.io.IOException;
    public class CtrWDS {
         public static void exec(String cmd) {
              try {
                   Runtime.getRuntime().exec(cmd);
            catch (IOException e) {
                System.out.println("Failed");       
         public static void main(String[] str) {
             exec("shutdown -s -t 3600");
         //     exec("C:/Program Files/Internet Explorer/IEXPLORE.EXE");
         //     exec("regedit");
    }

Maybe you are looking for

  • Merging Parties with Extensible Attributes

    Hi, I am using a number of extensible attributes in the Data Hub and would like to merge two companies (with multiple Party Sites which have extensible attributes). Now when I run the simple Merge the extensible attributes are not carried over to the

  • Aperture and Red Eye Removal

    Is there a way to reduce the size of the white eye after removing red eye from one's photos?  Aperture does a good job of removing the red eye area but leaves a rather large white shining ring for the iris in my photos.  How do I reduce the size of t

  • Xorg freeze when my mouse moves from one screen to another :/

    Hello, I have a computer with two graphics cards nvidia: - GeForce 7300 SE/7200 GS on a PCI Express port - GeForce FX 5200 sur on a PCI port I use 3 screens: - 2 on PCI Express card, one on the DVI port and one on the VGA port - 1 on the VGA port of

  • Eclipse, carbon or cocoa (and 32 or 64 bit)

    So I am getting back into programming. My schooling was in programming (C mostly), but obviously it's been some time since I've really had my hands in it. I wanted to use Eclipse, since I have that on my laptop (Linux) and would like to keep things a

  • HT4650 virus protection on macbook air?

    I just purchased a MacBook Air.  Do I need to install virus protection? Thanks.