This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help in compiling java files within the same directory structure

 
Diana Joseph
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
isn't that too correct in my scenario nicholas?
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a beginner's issue, really. It's all about your class path. See CompilingServlets for more info.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic