How do i call the method in a class using servlet

i am doing a project which need to use servlet to call a few methods in a class and display those method on the broswer. i tried to write the servlet myself but there are still some errors .. can anyone help:
The servlet i wrote :
package qm.minipas;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class test extends HttpServlet {
Database database;
/** Initializes the servlet.
public void init(ServletConfig config) throws ServletException {
super.init(config);
database = FlatfileDatabase.getInstance();
/** Destroys the servlet.
public void destroy() {
/** 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, java.io.IOException {
response.setContentType("text/html");
java.io.PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet</title>");
out.println("</head>");
out.println("<body>");
out.println("this is my class wossname"+FlatfileDatabase.getInstance()); // this is calling the toString() method in the instance of myJavaClass
out.println("this is my method"+FlatfileDatabase.getAll());
out.println("</body>");
out.println("</html>");
out.close();
/** Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.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, java.io.IOException {
processRequest(request, response);
/** Returns a short description of the servlet.
public String getServletInfo() {
return "Short description";
my methods which i need to call are shown below:
public Collection getAll() {
return Collections.unmodifiableCollection(patientRecords);
public Collection getInpatients() {
Collection selection=new ArrayList();
synchronized(patientRecords) {
for(Iterator i=patientRecords.iterator(); i.hasNext();) {
PatientRecord next=(PatientRecord) i.next();
if(next.isInpatient())
selection.add(next);
return Collections.unmodifiableCollection(selection);
public Collection getByAdmissionDate(Date dateOfAdmission) {
List selection=new ArrayList();
for(Iterator i=patientRecords.iterator(); i.hasNext();) {
PatientRecord next=(PatientRecord) i.next();
if(dateOfAdmission.equals(next.getDateOfAdmission()))
selection.add(next);
return Collections.unmodifiableCollection(selection);
public Collection getByAdmissionDates(Date from,Date to)
throws IllegalArgumentException {
if(to.before(from))
throw new IllegalArgumentException("End date must not be before start date");
List selection=new ArrayList();
for(Iterator i=patientRecords.iterator(); i.hasNext();) {
PatientRecord next=(PatientRecord) i.next();
Date nextAD=next.getDateOfAdmission();
if((nextAD.after(from)||nextAD.equals(from))
&&(nextAD.before(to)||nextAD.equals(to)))
selection.add(next);
return Collections.unmodifiableCollection(selection);
public Collection getByDischargeDates(Date from,Date to)
throws IllegalArgumentException {
if(to.before(from))
throw new IllegalArgumentException("End date must not be before start date");
List selection=new ArrayList();
for(Iterator i=patientRecords.iterator(); i.hasNext();) {
PatientRecord next=(PatientRecord) i.next();
Date nextAD=next.getDateOfDischarge();
if(nextAD==null)
continue;
if((nextAD.after(from)||nextAD.equals(from))
&&(nextAD.before(to)||nextAD.equals(to)))
selection.add(next);
return Collections.unmodifiableCollection(selection);
public Collection getByConsultant(String consultant) {
List selection=new ArrayList();
for(Iterator i=patientRecords.iterator(); i.hasNext();) {
PatientRecord next=(PatientRecord) i.next();
if(consultant.equalsIgnoreCase(next.getConsultant()))
selection.add(next);
return Collections.unmodifiableCollection(selection);
public Collection getByDischargeDate(Date dateOfDischarge) {
List selection=new ArrayList();
for(Iterator i=patientRecords.iterator(); i.hasNext();) {
PatientRecord next=(PatientRecord) i.next();
if(dateOfDischarge.equals(next.getDateOfDischarge()))
selection.add(next);
return Collections.unmodifiableCollection(selection);
public Collection getBySurname(String surname) {
List selection=new ArrayList();
for(Iterator i=patientRecords.iterator(); i.hasNext();) {
PatientRecord next=(PatientRecord) i.next();
if(surname.equalsIgnoreCase(next.getSurname()))
selection.add(next);
return Collections.unmodifiableCollection(selection);
public Collection getByWard(String ward) {
List selection=new ArrayList();
for(Iterator i=patientRecords.iterator(); i.hasNext();) {
PatientRecord next=(PatientRecord) i.next();
if(ward.equalsIgnoreCase(next.getWard()))
selection.add(next);
return Collections.unmodifiableCollection(selection);

please provide a detail description of your errors.

Similar Messages

  • How can we call the method of used controller?

    Hi All,
       i created two WDA Applications.( like YWDA1,YWDA2 ) . i am using the component WDA2 in WDA 1.and displaying the one view of WDA2 as popup window in WDA1 on action of one of the input element in the view of WDA1 by using the method l_window_manager->create_window_for_cmp_usage
    I have a button on the view of WDA2 which has appear in the popup window...how can i call the method which has binded to that button....and where should i code that...and i need to assign selected value in the popup window to input elemetn of view  WDA1
    Please help me to resolve this....
    Regards,
    Ravi

    You can not directly call view's event handler from other component.
    create a method in component controller of the second component and in the button click call the component controller method. ( also make the method as interface so that you can call it from other components )
    Now, you can call the interfacecontroller's method
    DATA: l_ref_INTERFACECONTROLLER TYPE REF TO ZIWCI__VSTX_REBATE_REQ_WD .
      l_ref_INTERFACECONTROLLER =   wd_This->wd_CpIfc_<comp usage name>( ).
      l_ref_INTERFACECONTROLLER->Save_Rr(
        STATUS = '01'                       " Zvstxrrstatus
    save_rr is the method of second component controller

  • How do you call a method from  another class without extending as a parent?

    How do you call a method from another class without extending it as a parent? Is this possible?

    Why don't you just create an instance of the class?
    Car c = new Car();
    c.drive("fast");The drive method is in the car class, but as long as the method is public, you can use it anywhere.
    Is that what you were asking or am I totally misunderstanding your question?
    Jen

  • How Can I Call the method in WAR project's class?

    Message was edited by: JUNHA SHIN

    I have one correct Web Moudule Project.
    The EAR project(EmployeeCardJdoEar) added the WAR archive
    (EmployeeCardJdoWar) is run correctly.
    I want to add the war archive to my WD project.
    because, the war project contain business logic to be reused.
    so. i had enrolled in my WD project's properties ->
    Web Dynpro References -> Sharing References ->
    sap.com/EmployeeCardJdoEar.
    but, this method in WAR(EmployeeCardJdoWar) occurs Exception.
    Context ctx = new InitialContext();
    pmf = (PersistenceManagerFactory)
               ctx.lookup("java:comp/env/jdo/defaultPMF");
    I think lookup call is not run correctly.
    But, this lookup is run correctly in my EAR project.

  • How can i call the browser to open URL using ABAP ???

    Hi all ,,
    Could you help please to solve this case ??? :).
    I'm working out a plan to open URL internet address using ABAP program ..
    Could you share to me the command or the way to run the internet browser (e.g. internet explorer) in order to run some URL address ???
    If you don't mind ..
    Could kindly please give the steps to make it .. ???
    Tks a lot ..
    i'll appreciate any responses.
    Best regards,
    Niel.

    Hi,
    CALL FUNCTION 'CALL_BROWSER'
                 EXPORTING
                      URL                    = URL "http://,,,,,,"
                      BROWSER_TYPE           = ' ' "'SAP Help Viewer'
                      CONTEXTSTRING          = 'Business Browser'
                 EXCEPTIONS
                      FRONTEND_NOT_SUPPORTED = 1
                      FRONTEND_ERROR         = 2
                      PROG_NOT_FOUND         = 3
                      NO_BATCH               = 4
                      UNSPECIFIED_ERROR      = 5
                      OTHERS                 = 6.
          ENDIF.
    Pls. reward if useful....

  • Calling main method in another class using command line arguements

    Hi
    My program need to use 4 strings command line arguments
    entered in Project properties/Run/Application Parameters
    java programming for beginners // arguments
    The program needs to call main in the second class 4 times using argument 1 the first call, argument 2 the second call on so on.
    So the output wil be
    java
    programming
    for
    beginners
    import java.lang.*;
    public class First extends Second{
      public static void main(String[] args) {
        for(int i = 0; i < args.length; i++){
           Second.main(args); // Error I think
    import java.lang.*;
    public class Second {
    public static void main(String[] args){
    System.out.println(args[0]);
    "First.java": Error #: 300 : method main(java.lang.String) not found in class Second at line 6, column 15
    I am only a beginner with little knowledge of java so can the code be as basic as possible

    Your style looks quite bad for starters..... Hows
    this://import java.lang.*; /* NOT NEEDED */
    public class First extends Second{
    public First(String s) {
    super(s);
    public static void main(String[] args) {
    for(int i = 0; i < args.length; i++){
    new First(s);
    public class Second {
    public Second(String s)
    System.out.println(s);
    NOT NEEDED:
    public static void main(String[] args){
    System.out.println(args[0]);
    }My question to you: Do you understand why my code
    works? (does it do what you want?)I think since this is some kind of lesson, the OP have to implement some way to use the main method of the Second class as it is, that is, with String[] args. I think this lesson is interesting exactly because of this requirenment. But, anyway, I don�t know, that is just my assumption...

  • How Can I Call a method in iView  ,which is in another iView

    I Have 2 iViews i want to call a method in Iview which is i another iView
    Thanks and Regards
    Prasad.Y

    Hi Prasad,
    first, welcom at SDN.
    Next, let us clarify some wording:
    A <i>PAR</i> is a <i>Portal ARchive</i>. It is a zip in a certain format. It contains a <i>portal application</i>.
    A <i>portal application</i> consists of <i>components</i> and/or <i>services</i>.
    An <i>iView</i> is somehow an "instance" of a <i>component</i>. It is created within the portal. There are <i>no iViews in a PAR</i> (like: "There are no objects in a JAR (but classes).").
    With this in mind, you know that the question does not work, for iViews don't have "methods".
    If you ask how you can call a method of a class belonging to a different component (but within the same portal app), it is no problem at all, each class has access to each other class within the same portal app (in fact, one has to differentiate between public and private part, but we don't want to go so far). To call use a class belonging to (the public part of) a different app, you will have to set the SharingReference within portalapp.xml.
    If that's what you're looking for - great.
    If not, ask again, but far more detailed.
    Hope it helps
    Detlev
    PS: Please consider to reward points for helpful answers. Thanks in advance.

  • Call the method of a ejb??

    hi!
    I get EJB refrence ,How can I call the method of it?(I use the stand-alone application client)
    code:
    import javax.naming.*;
    //import javax.naming.InitialContext;
    import javax.rmi.*;
    import java.util.*;
    //import hello.*;
    public class jndi {
    public static void main(String[] args) {
    try {     
    Hashtable env = new Hashtable();
         env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
    env.put(Context.PROVIDER_URL, "iiop://localhost:3000");
         Context initctx = new InitialContext(env);
         Object objref = initctx.lookup("HelloEJB");
    the method I want to call
    } catch (Exception ex) {
    System.err.println("Caught an unexpected exception!");
    ex.printStackTrace();
    Because it is the stand-alone .I can not to convert the objref:
    HelloHome helloHome =(HelloHome)objref;
    what can I do???

    It still can work.
    Tere is a ClassCastException.
    And the the class name of the objref is "com.sun.corba.se.internal.iiop.CDRInputStream_1_0$1".
    but my EJB is named HelloEJB.
    Is the object which I want to call????

  • Calling a Method of Interface by using Object

    Hi All,
    I want to use a method of a class which will be IF_ABC_XYZ~ <amethod> ( ). how can i use this method in my program , I have the instance of the class which have the above mentioned method?
    Thanks & Regards
    Pavan

    thanks
    here the case is like this
    data :
           lv_type  TYPE REF TO  IF_some xyz.
    now by using a static class method i am able to get the return type equal to lv_type i.e
    CALL METHOD cl_someclassname=> amethod ( )
       IMPORTING
           type      =  lv_type.
    now when i debug and see lv_type is having a class name inside it. I want to use a method of this class.
    How can I call the method which Iam able to see in the lv_type when i debug.

  • Help on Calling a method from another class

    how can i call a method from another class.
    Class A has 3 methods
    i just want to call only one of these 3 methods into my another class.
    How can I do that.

    When i am trying this
    A a=new A;
    Its calling all the methods from class A. I just want
    to call a specfic method.How can it be done?When i am trying this
    A a=new A();
    Its calling all the methods from class A. I just want to call a specfic method.How can it be done?

  • Calling a method in Runnable Class

    Hello I am trying to water this down but how can I call a method in my class
    If I am passed only thread t.
    MyClass mc = new MyClass();
    Thread t = new Thread(mc);
    t.start(); //works because it is a method of Thread
    t.myMethodInMyClass (); // wont work because it cant find it
    I have attempted casting to MyClass but I get CCException.
    Any help would be wonderful..
    cheers and thanks in advance.
    Scott

    Well, you could potentially have too many things in one class. You may want to try and modularize your classes more. But 'if in several situations [you] need different things to run'... well, the logic is just going to have to be there for that in some form.
    Now, if you've already performed the logic to determine what to run and you are going to have to perform the logic again (in your run() method), then there is a flaw in your design.

  • How to call a method of a class where the name of method is string

    i have a method of a class in the form of a string and i have the object of the class to which it belongs .what i want to do is call this method.
    for ex:
    S1 s=new S1();
    // this is the object of my class. this class has one method called executeMe()
    String methodname="executeMe";
    //i have the name of the method with me in the form of string.
    so how can i call the class's method in this scenario from the string like what should i write in sucha way that i get s.executeMe(); it is not presumed that this will only be the method that will be called. there maybe some other method too and it has also to be called this way. so please guide.

    S1 s = new S1();
    String name = "executeMe";
    Method m = s.getClass().getDeclaredMethod(name,null); // no parameters
    m.invoke(s,null);Built from memory, maycontain flaws.

  • How to call the method of a Business Object?

    Hi,
    Can someone guide me how to call the method of a business object?
    For example, I want to use the method SalesDocument.Copy of the Business Object VBAK. How can I do that? If you are familiar with any similar scenario please help.
    Regards,
    Renjith Michael.

    Hi
    double click on the copy  and
    go to abap tab
    there u can get functionmodule name
    u can call that
    Rewards if helpful

  • How to call the methods of JAR file into webDynpro Environment

    Hi All ,
             I have a requirement to call the methods of a JAR file into
             WebDynpro Environment. can anybody suggest me How this can be achieved. I Have a JAR file named FastTrack.API
    which contains few methods and i want these methods to be accessable into WebDynpro as other methods.
    Plz Somebody help me to sort this out.
    Regards,
    Deepak.

    Deepak,
    Please follow these 2 steps:
    1. Add jar into webdynpro project
            Right Click on ur project -> Select properties -> Java Buil path -> Choose Libraries Tab -> Add External Jars -> add the file from ur computer
    2. Use the jar
          write the import statement in your webdynpro code to utilize the properties of added jar.
    Thanks & Regards,
    Ram

  • How can I call the create method in BO from Application Service

    Hello!
    When I create a Business Object, CAF generates some methods automatically.
    How can I call the create method in the BO from Application Service logic?
    When i call the method then the entityManager and the sessionContext is NULL.
    How can I initialize this?
    Can anybody help me?
    Thanks, Thomas

    If you are using CE 7.11...
    1) In the Application Services, add the BO as dependant object in dependencies tab.
    2) In the implemention, add the following codes to call create method of the BO:
    this.get<BO>.createMethod();
    julius

Maybe you are looking for