Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Doubt in Servlet (https://www.askmehelpdesk.com/showthread.php?t=390117)

  • Aug 24, 2009, 04:45 PM
    pglgops
    Doubt in Servlet
    Hi Guys..

    I got error when I call plain code in servlet..
    Kindly look my program

    BeerExpert.java


    import java.util.*;
    public class BeerExpert
    {
    public List getBrands(String color)
    {
    List l = new ArrayList();
    if(color.equals("amber"))
    {
    l.add("Gopal");
    l.add("Senthil");
    }
    else
    {
    l.add("Sorry");
    l.add("Ma");
    }
    return (l);
    }
    }

    it compiles fine


    BeerSelect.java

    import javax.servlet.*;
    import java.io.*;
    import javax.servlet.http.*;
    import java.util.*;

    public class BeerSelect extends HttpServlet
    {
    public void doPost(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException
    {
    resp.setContentType("text/html");
    PrintWriter pw=resp.getWriter();
    String c = req.getParameter("color");
    BeerExpert br = new BeerExpert();
    List result = br.getBrands(c);


    Iterator it = result.iterator();
    while(it.hasNext())
    {
    pw.println("<br> Try:"+it.next());
    }
    }
    }

    This BeerSelect.java will always produce compile time error..

    E:\>javac BeerSelect.java
    BeerSelect.java:13: cannot find symbol
    symbol : class BeerExpert
    location: class BeerSelect
    BeerExpert br = new BeerExpert();
    ^
    BeerSelect.java:13: cannot find symbol
    symbol : class BeerExpert
    location: class BeerSelect
    BeerExpert br = new BeerExpert();
    ^
    2 errors

    respond me soon... I m confussed now..
  • Sep 4, 2009, 03:26 AM
    patilrok

    One thing you can try is first try to write both the java files in single file..
    Means copy BeerExpert.java code into BeerSelect.java file n then try to compile and run it.
  • Sep 4, 2009, 03:27 AM
    patilrok
    Other possibility is that the both files may be in different folders, if so put them in same folder..
  • Sep 4, 2009, 04:28 AM
    pglgops
    Lot of thanks for your reply...

    I also try that... put 2 programs in same folder(w/o packages) and compile it...

    Same error occurs...
  • Nov 15, 2009, 09:46 PM
    jmd814

    Often the local directory is not in the classpath, to add it, simply add the following to your options: '-cp .'

    This will force the classpath - which is the locations for which it will look for other files needed to compile the current program - to look in the current directory

  • All times are GMT -7. The time now is 08:35 PM.