Methods in Servlets

I want to seperate my html display output from my programs logic. In an application I would just make a method to do this. I have had a problem doing this with my servlet. I get the error is:
BP_Test.java:32: missing method body, or declare abstract
     private void displayDetails ( HttpServletResponse resp,
I have defined the method as follows:
     private void displayDetails ( HttpServletResponse resp,
                                                  int empNo );
          resp.setContentType ( "text/html" );
          PrintWriter out = resp.getWriter ();
          out.println ( "<HTML>\n<HEAD>" );
I call the method as follows within a doPost method:
displayDetails ( response, employeeNo );
If any one could give me any help I would be very grateful.
Bronek

private void displayDetails ( HttpServletResponse resp,int empNo );Right here you have a semi-colon after the method declaration, so it's not seeing the body of the method below. Removing the semicolon should fix it.
David Black
          resp.setContentType ( "text/html" );
          PrintWriter out = resp.getWriter ();
          out.println ( "<HTML>\n<HEAD>" );

Similar Messages

  • Calling a method of servlet

    How to call a method of servlets like we do in struts like "get.do?method=getData". I know servlets are called defacult method either dopost or doget are called but can i call any other in the servlet and if yes how can i do that?

    May be your servlet is not able to lookup the EJB. You can use some print statements and see whether lookup ok or not.
    Just a guess.
    Plese get back, if any queries.
    Thanks,
    Rakesh.

  • Getting error while calling ejb business methods from servlet

    Hi
    Iam getting error when i try to call a ejb method from servlet.Error is
    "com.netscape.server.eb.UncheckedException: unchecked exception nested exception is:java.lang.NullPointerException".
    I build the application and deployed it successfully.Iam using IAS 6.O with windows NT 4.0.
    This is just a method which takes values from database and return as an array of bean to servlet.
    Any help on this.Thanks Shank

    Hi
    I was using the session bean.Your suggestion helped me a lot.Perfect.
    I debug my program and found that from ejbCreate()exception is getting.
    I was getting the datasource object thro ejb create() initialisation.
    Somehow the look up jndi which i mentioned was not interpretting from ejb-jar.xml ias-ejb-jar.xml and datasource ref .Due to this iam getting jndi Namenotfound exception which in turns to null pointer as datasource is getting null.
    when i hardcoded in the ejb the the jndi name for datasource it is working fine.Bit worried all the existing ejbs working with the xml referenced datasource and jndi,but when i added a new ejb with same properties it is failing to get the jndi name.
    Piece of code from ias-ejb-jar.xml
    <resource-ref>
              <res-ref-name>myDataSource</res-ref-name>
              <jndi-name>jdbc/nb/myData</jndi-name>
    </resource-ref>
    Piece of code from ejb-jar.xml
    <resource-ref>
              <res-ref-name>myDataSource</res-ref-name>
              <res-type>javax.sql.DataSource</res-type>
              <res-auth>Container</res-auth>
    </resource-ref>
    Thanks a lot meka

  • Why Do We Have To Call super.init(config); in init() method of servlet?

    Hi, everyone..
    I wonder why we call super.init(config) in init method of servlet... If i dont call it ; when i try to get servletcontext in service method it throws java.lang.NullPointerException...when we call super.init() , what is happening behind the scene? If anybody has a technical explanation for my question , i will be very pleased...
    THX FOR YOUR FUTURE REPLIES IN ADVANCE....

    I am sorry about the uppercases and i dont want to seem smart on java forums... Anyway, m8 this is the thing that i know... i meant; for instance when we override doGet or doPost method ; we dont need to override init method; but the server loads the servlet and we can get the context of the servlet in these methods easily by calling getServletContext() method; however when we want to call service method implicitly by jndi, servlet needs to be loaded and init method must call its parent...(i also write down in web.xml <load-on-startup>.... for that servlet).
    thx for your replies in advance....

  • How to expose custom methods of servlet as web services

    Can i know how to expose the custom methods of the servlet as web services. if it is not posssible then what alternate ways are possible other than ejbs?
    regards

    Hi
    I want to know that whether the custom methods of servlet can be exposed as webservices or not?
    Secondly is there init method like we have in servlets so that we can do all the one time loading in the init() method.
    regards

  • Who calls doget() method of servlet

    hello all,
    i have typical customized webserver.
    the problem i have with that is when i configure it with IP address and when i send a request through browser using HOST NAME ,its not recognizing.
    the same happens vice versa
    that is : set up host name in the http server, and when try a request through IP Address using a web browser.
    can any body clear me who calls the doGet() method of servlet. if it is USER AGENT of web browser, is there any operation executes between
    USER AGENT - DoGet() method of servlet?
    regards
    R
    Message was edited by:
    LoveOpensource

    The servlet is on the server, the browser is on the client, so, do it think it possible (unless the browser is written in Java and does it's browsing with RMI, which is patently absurd) that the browser call doGet()?
    It is rather obvious, that the browser sends an HTTP request to the Application Container (or a web server such as apache which then uses some module to communicate with the Application Container, but the end effect is the same), and that Application Container calls the doGet() method.
    Edit: And man am I slow and "wordy".

  • Database connection not closed in Destroy()  method of servlet

    Hi,
    I have a problem with my deployed web application. At first, I thought Glassfish was messing up on me, and after checking the log I could see plenty of null pointer exceptions being thrown at lines in my code where I generate prepared statements from my connection object. I have been initialising my connection in the Init() method of all my classes, and equally, I've been closing it in Destroy(). I can only imagine that destroy() isn't being called - since the log clearly shows "connection success" messages but not "connection closed" messages. I am connecting to the servlets via a J2ME app on my mobile phone. Does connecting in this way somehow not invoke the destroy method when the servlets work is complete? Am I going to need to move all my connection initilisation and closing into the necessary doGet/doPost methods of each of my servlets?
    Chris

    You shouldn't be keeping the connection that long open. It's a bad design. It will timeout sooner or later and your complete application will crash. Always acquire and close the connection in the shortest possible scope, preferably just in the same method block where you process the query and/or results. If you want to improve performance while connecting, consider using a connection pool.
    Back to the actual problem: a servlet is created only once during application's lifetime and not during every request as you appears to think.
    You may find this tutorial useful to read on about using the DAO pattern in JSP/Servlet.
    [http://balusc.blogspot.com/2008/07/dao-tutorial-use-in-jspservlet.html]

  • Is it possible to call a java method from servlet

    Hi All,
    I am trying to import a java class to my servlet and call a method of that class, is this possible. I am getting an error while importing the class.
    I am using tomcat, have put my class files in th path
    \WEB-INF\classes\com\kiran
    My java goes like this
    package com.kiran;
    import java.sql.*;
    import javax.sql.*;
    public class DbCon
    { Connection con=null;
    public Connection getCon()
    -----return con;
    catch(Exception e){ return con; }
    and my aim is to call getCon() from my servlet. which is as follows
    package com.kiran;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import com.kiran.DbCon;
    public class check extends HttpServlet
    DbCon db;
    i am not able to compile my servlet, err is --> cannot find symbol DbCon..
    How can i import the class, do i require any entries in web.xml ?
    expecting your advice..
    Thanks in advance
    Best Regards,
    Kiran

    Ok, first off, if you are testing in tomcat (and as you said you are placing the class files in the path), you already compiled this classes, right? Otherwise I don't see how you placed your classes in /WEB-INF/classes/. Note that you will need two class files (based on your code. If not, then I'm missing part of the question. Typically, your IDE will help you with this problem a lot. The only thing that seems confusing is the catch (Exception e) statement which needs to be as part of a method (I assume this is a typo on your part).
    If your problem is at runtime, don't forget to configure your web.xml to see your servlet.

  • 'Error: 500 SC_INTERNAL_SERVER_ERROR' after init() and before doGet() method in servlet.

    Hi to you all,
    I have been working with ias6.0 sp2 on Unix.
    I have a simple web application with servlets and packaged auxiliary classes. Deployment seems all good. But when I try to call my first servlet with URL, I get this message on the navigator : "Error: 500 SC_INTERNAL_SERVER_ERROR
    null ".
    In the log file, I have that :
    "error: Exception: SERVLET-execution_failed: Error in executing servlet myServlet: java.lang.NullPointerException [...]
    at com.netscape.server.servlet.servletrunner.ServletInfo.checkAuthorization (Unknown source)
    error: APPLOGIC-caught_exception: Caught Exception:
    java.lang.NullPointerException
    at com.netscape.server.servlet.servletrunner.ServletInfo.popPrincipalFromTLD (Unknown source )
    My application works well with iws. So, what's up ?
    The init() method is executed, but not the doGet() one.
    Well, hear you soon !
    Paul-Emile

    Hi,
    Although it is difficult to point out the place where the error exactly occurs, I can suggest the reasons. The possible place for error to occur normally lies in the database connectivity. When the HttpServlet is not able to communicate with the database or encountered errors while communicating with the database. Please let me know if this helps.
    Regards
    Raj

  • Calling method from servlet

    hi,
    I want to call a method of an object that is available in a program already running, with parameters passed from the servlet.
    How to do it .
    Thanks.

    Pls be patient with me. I tried my best and couldn't achieve what I want.
    I provide the skeleton of what I have done and what I want to do.
    I have my core part in /home/raja/Service/Core.java, the only java file in Service folder. When I compile it I get some four class files(which are used in Core.java file internally). I don't compile it as a package but as a single file.
    I run the program in the same folder and in main method I use an infinite loop to keep the program running infinitely.
    And I have a html as, usr/local/jakartaTomcat../webapps/servlets-examples/input.html. which simply gets an input string and submits to /servlet/Insert servlet class which is in ../servlets-examples/classes/Insert.class.
    It put the string in DB which works fine. Also I made a package in ...servlet-examples/classes/Service in which I uploaded Core.java and compiled it and got the class files in it as a package.
    In Insert class file I imported Service.*. In Insert class file I put a line like this. Core.putInPool(submittedString) which is a static method.
    When I submit input.html , the string is put in DB, but it is not submitting to the program already running.
    What I want to do is, I want to submit the string to the program that is running in /home/raja/Service/.
    This is the program running in /home/raja/Service.
    public class Core {
         static ThreadPool bc= new ThreadPool(10);
         public static void putString(String someStr) {
              bc.putInPool(someStr);
         public static void main(String args[]) throws InterruptedException {
              BufferedReader dataIn = new BufferedReader(new InputStreamReader( System.in) );
              while(true) {
                   System.out.println("\f 1.Insert\n2.option2Enter Ur choice:");
                   try{
                        ch = Integer.parseInt(dataIn.readLine());
                                   String string="";
                        switch(ch) {
                             case 1: System.out.println("\nEnter the String:");
                                  string = dataIn.readLine();
                                  bc.putInPool(string);
                                 .....In Insert.class servlet,
                                    string = req.getParameter("userInputString");
                                    out.println("Submitted");
                        Core.putInPool(string);

  • Service method  of servlet  is called repetitively as response time is more

    Problem: when we try to retrieve data for a particular input, then the retrieve
    query takes longer time which is as expected i.e more than five minutes as our data ware house is large and the where clause is very complex. After 5 mins what happens is that the service
    method in the servlet call is made again and so the retrieve process as if it was
    triggered again,where as no one has triggered it. This happens every 5 mins and the overall
    process hangs forever.pl help if any answer
    thanks in adv.
    M.S.Chandrasekhar

    Hi ,
    Hello ,
    Try this code ,
    Class classObject = Class.forName("SecondServlet");
    SecondServlet servlet = (SecondServlet)classObject.newInstance();
    servlet.init(getServletConfig());
    System.out.println("Before calling the service() from TestServlet");
    servlet.service(req,res);
    servlet.destroy();
    Regards ,
    Venkat

  • Service method of servlet is called repeatedly by 9ias

    Problem: when we try to retrieve data for a particular input, then the retrieve
    query takes longer time which is as expected i.e more than five minutes as our data ware house is large and the where clause is very complex. After 5 mins what happens is that the service
    method in the servlet call is made again and so the retrieve process as if it was
    triggered again,where as no one has triggered it. This happens every 5 mins and the overall
    process hangs forever.pl help if any answer
    thanks in adv.
    M.S.Chandrasekhar

    Hi MS,
    My guess (and it can only be a guess, I'm afraid, based on the [lack
    of] information you have supplied) is that you are hitting some sort
    of timeout value, which is determined by a setting in one of your
    configuration files.
    So as Prasad has already mentioned, more information would help us
    to help you.
    Good Luck,
    Avi.

  • 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);
        }

  • How to call the EJB methods from servlet/jsp

    Hello ,
    i have write one ejb signOn having the method validateUser(username,password).i can able to call this function from client.java class.i want to know whether i can call this function from servlet.if yes then where to write that servlet and web.xml file.
    At present i m using weblogic server 8.1and i create directory call c:\ejb\demo and put the ejb files(home ,remote,ejb class ,client.java) then i have created .jar file and put in application file.
    Now i want to create a servlet for that i have to create a new directory and put the servlet,web.xml,weblogin-web.xml file and then create one .war file and put in application directory or do some thing extra.Please help me.
    Thanks In Advance
    [email protected]

    I think this might not be the most appropriate forum for your question. You might try a forum about ejb, or weblogic, or jndi.

  • Can an applet call one of the methods of servlet??

    hi everyone...
    i m very new servlet and applet programming and i have come accross a problem....
    i m using a applet which establishes connection with the servlet(residing on server)..i want to use few of the methods of the servlet....
    now is it possible tfor me to call the methods of this servlet using its object.???
    please help me..
    thanx in advance

    first of all thanx a lot for the reply...
    but i wanted to know can an applet call any other
    function of servlet other than get and post....as i
    hacve defined some more functions in servlet..
    please reply...I did this a while back (2003/4?) and unless it's changed you cannot do it directly, it must be GETor POST, then you could just use conditional logic to invoke another method.

Maybe you are looking for

  • .m4v to idvd

    i've downloaded some movies (.m4v) and converted them to a dv format. The file size was 8Gig!!!! Is there any other way to format a movie file to idvd using isquint or handbrake???? I tried converting the .m4v file in imovie, which took 2 hours, but

  • Error in multiprovider

    Pls help me out in the problem My multiprovider is created using 2 cubes say cube1 and cube 2. I created a query on this multiprovider , but the results was strange as shown in the attched excel sheet. In Identification tab I have checked Sales Doc n

  • .xhtml file in ADF stack

    Hi Experts, can we have "*.xhtml*" file in ViewControler project instead of .jspx file ? thnks

  • JSF event on a template part of page does nothing

    I created a page template which also changes locale, but when I apply the template to an JSF page. The change locale code does not work at all. It is like the backing bean of the template does not exist. Template code: <h:form> <h:selectOneMenu style

  • Vcd file generation for the T2 core

    Hello everybody, I want to generate a vcd file of a specific unit of the T2 using vcs (I haven't Debussy). Which are the compile time flags and the runtime flags to be set using the sims script? I tried the -enableEvcd and vcsd and cli at compile tim