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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

servlet importing model

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Head First Java, Ch 3, page - 85

While trying to compile the servlet code i get the following error -

C:\j2sdk1.4.2_14\bin>javac -classpath c:/program~1/apache~1/tomcat5.5/common/lib
/servlet-api.jar:classes:. -d f:/myprojects/beer/classes f:/myprojects/beer/src/
com/example/web/BeerSelectModel.java
f:/myprojects/beer/src/com/example/web/BeerSelectModel.java:3: package com.examp
le.model does not exist
import com.example.model.*;
^
f:/myprojects/beer/src/com/example/web/BeerSelectModel.java:19: cannot resolve s
ymbol
symbol : class BeerExpert
location: class com.example.web.BeerSelectModel
BeerExpert be = new BeerExpert();
^
f:/myprojects/beer/src/com/example/web/BeerSelectModel.java:19: cannot resolve s
ymbol
symbol : class BeerExpert
location: class com.example.web.BeerSelectModel
BeerExpert be = new BeerExpert();
^
f:/myprojects/beer/src/com/example/web/BeerSelectModel.java:21: cannot resolve s
ymbol
symbol : variable result
location: class com.example.web.BeerSelectModel
Iterator it = result.iterator();
^
4 errors

Code for Servlet BeerSelectModel -

package com.example.web;

import com.example.model.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class BeerSelectModel extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Beer Selection Advice<br>");
String c=request.getParameter("color");
out.println("<br>Got beer color" + c);

BeerExpert be = new BeerExpert();
List results = be.getBrands();
Iterator it = result.iterator();
while(it.hasNext()){
out.print("<br>try: "+ it.next());
}
}
}


Code for Model BeerExpert -

package com.example.model;

import java.util.*;

public class BeerExpert {
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);
}
}

Can anyone please come to my rescue :-(

NOTE - i have installed ant tool, but it seems to be a tedious task using it. Can someone please help me the normal way.
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi Ashish -

Not sure whether you're just studying servlets or servlets and the SCWCD exam ?

I'll take a stab at trnasferring this over to the servlets forum
 
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi Ashish,

I see that you have already asked this question here:

https://coderanch.com/forums/

It would be most helpful if you ask your question once, giving other members the chance to respond.

I am closing this topic, so that the discussion may continue in the thread linked to above.

Katrina Owen,
Saloon Staff
    Bookmark Topic Watch Topic
  • New Topic