komputergeek
Post your code here.
Here first i am providing the whole directory structure and that is followed by coding of .java files.
....................................
My directory structure is:
C:
MyProjects: (this is folder) EVERYTHING followed by ":" is folder
beerV1:
src:,classes: (sub-folders of berV1)
................................................................
src folder contains:
src:
com:
example:
web:,model: (sub-folders of example)
web folder contains:
BeerSelect.java (file)
>>>>
model folder contains:
BeerExpert.java (file)
................................................................................
similarlly classes folder contains:
classes:
com:
example:
web:,mode:l
web:
(this folder does not contain file yet.BeerSelect.class file goes here after successful compilation)
model:
BeerExpert.class
...............................................................................
now when i compile BeerSelect.java like:
C:\MyProjects\beerV1>javac -classpath C:/tomcat/common/lib/servlet-api.jar -d classes src/com/example/web/BeerSelect.java
Three ERRORs:
src/com/example/web/BeerSelect.java:3: package com.example.model does not exist
import com.example.model.*;
^
src/com/example/web/BeerSelect.java:17: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();
^
src/com/example/web/BeerSelect.java:17: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();
^
3 errors
.............................................................................
BeerExpert.java has code:
package com.example.model;
import java.util.*;
public class BeerExpert
{
public List getBrands(String c)
{
List<String> arr = new ArrayList<String>();
if(c.equals("amber"))
{
arr.add("Jack Amber");
arr.add("Red Moose");
}
else
{
arr.add("Jail Pale Ale");
arr.add("Gout Strout");
}
return(arr);
}
}
.............................................................................
BeerSelect.java has code:
package com.example.web;
import com.example.model.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class BeerSelect extends HttpServlet
{
public void doPost(HttpServletResponse response,
HttpServletRequest request)
throws IOException,ServletException
{
String c = request.getParameter("color");
BeerExpert be = new BeerExpert();
List a = be.getBrands(c);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Selection Beer Advice<br> ");
Iterator i = a.iterator();
while(i.hasNext())
{
out.println("<br> try: "+ i.next());
}
}
..............................................................
MAIN PROBLEM LIES WITH IMPORTING OF PACKAGE IN BeerSelect.java
and ERROR is Package not exist but it exist...