• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Need help in compiling java files within the same directory structure

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am practicing Head First Servlets and JSPs at the moment in
progress to my scwcd certification. I am struck in compiling java
file residing in the same directory structure.

I have a BeerExpert_model.class file in the directory
com.example.beermodel
and
BeerSelect.class file in the directory com.example.beer.
BeerSelect.class calls BeerExpert_model class. But the package,
com.example.beermodel isn't being recognised while compiling
BeerSelect.class.

I have copied both these classes below:




BeerSelect.java:

package com.example.beer;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import com.example.beermodel.BeerExpert_model;
import java.util.*;

public class BeerSelect extends HttpServlet
{
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
String str = request.getParameter("color");
//out.println("<br>Get Beer Color "+str);
BeerExpert_model bem = new BeerExpert_model();
List result = bem.getBrands(str);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Beer Selection Advice<br>");
Iterator it = result.iterator();
while(it.hasNext())
{
out.print("<br> try"+it.next());
}
}
}





BeerExpert_model.java:

package com.example.beermodel;
import java.util.*;
public class BeerExpert_model
{
public List getBrands(String color)
{
List brands = new ArrayList();
if(color.equals("amber"))
{
brands.add("Jack amber");
brands.add("Red moose");
}
else
{
brands.add("Jail Pale Ale");
brands.add("Gout Stout");
}
return(brands);
}
}



Please help me resolve this.

Thanks and regards,
Diana
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Think of the dots in the package name being translated to the slashes of directory structure: Where would everything be, or need to be put?
 
Diana Joseph
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
isn't that too correct in my scenario nicholas?
 
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a beginner's issue, really. It's all about your class path. See CompilingServlets for more info.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic