Ask Experts Questions for FREE Help !
Ask
    pglgops's Avatar
    pglgops Posts: 2, Reputation: 1
    New Member
     
    #1

    Aug 24, 2009, 04:45 PM
    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..
    patilrok's Avatar
    patilrok Posts: 8, Reputation: 1
    New Member
     
    #2

    Sep 4, 2009, 03:26 AM

    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.
    patilrok's Avatar
    patilrok Posts: 8, Reputation: 1
    New Member
     
    #3

    Sep 4, 2009, 03:27 AM
    Other possibility is that the both files may be in different folders, if so put them in same folder..
    pglgops's Avatar
    pglgops Posts: 2, Reputation: 1
    New Member
     
    #4

    Sep 4, 2009, 04:28 AM
    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...
    jmd814's Avatar
    jmd814 Posts: 10, Reputation: 2
    New Member
     
    #5

    Nov 15, 2009, 09:46 PM

    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

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

I doubt it. [ 6 Answers ]

I do not mean to offend anybody.... But is psychic really real? I think it kind of hard to believe... :confused:

Unable to include servlet package [ 1 Answers ]

I have installed apache tomcat 5.5 n also set the classpath but at the time of compiling the servlet prog it is giving error unable to include import javax.servlet.*; n cannot find many symbol like HttpServlet,ServletConfig... So give me some answer on this.

I need help with a doubt I have! [ 4 Answers ]

I want to know if I am going to have children since I have been trying for 3 years now.And if I am how many?Will it be boys or girls?My D.O.B is 12-17-1983. :rolleyes:


View more questions Search