Bookmark Topic Watch Topic
  • New Topic

servlet importing model  RSS feed

 
Ashish Modi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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.
 
Bert Bates
author
Sheriff
Posts: 8945
17
  • Mark post as helpful
  • send pies
  • 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
 
Katrina Owen
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Ashish,

I see that you have already asked this question here:

http://www.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
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!