Forums Register Login

servlet importing model

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
Message for you sir! I think it is a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


Reply locked
This thread has been viewed 900 times.
Similar Threads
Error: package com.example.model does not exist
compiling servlet
weird problem
Problem in accessing model in diffeerent package(Servlet-HFS)
can't compile a servlet
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:41:39.