Win a copy of Head First Android this week in the Android forum!
  • 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 Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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: 22509
122
Eclipse IDE Spring VI Editor 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic