Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compilation Problem in CHAP3 example

 
satya mahapatra
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My 1st version servelt is workin perfectly. Then I created the model BeerExpert and compile it. Its also done. Now when I m trying to compile 2nd version servlet by calling model its not recognising model class. Its showing

C:\MyProjects\beerV1>javac -d classes src\com\example\web\BeerSelect.java
src\com\example\web\BeerSelect.java:20: cannot find symbol
symbol : class BeerExpert
location: class com.example.model.BeerExpert.BeerSelect
BeerExpert be=new BeerExpert();
^
src\com\example\web\BeerSelect.java:20: cannot find symbol
symbol : class BeerExpert
location: class com.example.model.BeerExpert.BeerSelect
BeerExpert be=new BeerExpert();
^
2 errors

please help
 
Manish Shah
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure that the package structure is BeerExpert.BeerSelect.
I think the package structure is incorrect. Else i need to refer.
 
satya mahapatra
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I checked it. Its correct only.
 
Imran Vohra
Ranch Hand
Posts: 77
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you import your model class in servlet?

Thanks
Imran
 
satya mahapatra
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yah Imran I have imported also. My code is as follows
For Servlet BeerSelect
------------------------------------

package com.example.web;

import com.example.model.BeerExpert;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;


public class BeerSelect extends HttpServlet{

public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,

IOException{

res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("Beer Selection Advisor<br>");
String c=req.getParameter("color");

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

Code Of mode BeerExpert
-------------------------------------
package com.example.model;
import java.util.*;

public class BeerExpert{
public List getBrands(String color){
List<Object> brands = new ArrayList<Object>();
if(color.equals("Red"))
{
brands.add("H");
brands.add("Jack Amber");
}

else{brands.add("Jail Pale Ale");
brands.add("Gout Stout");
}

return(brands);
}
}
 
satya mahapatra
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Friends I m using JDK1.5. Is that the problem???
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. It's a CLASSPATH problem. Did you manage to go up to SCWCD without knowing about the CLASSPATH ?

http://faq.javaranch.com/view?HowToSetTheClasspath
 
satya mahapatra
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Satou,
Yah managed to go to SCWCD without knowin Classpath.But now I ant to master it.
Thanks for your valuable information. Because of that I am able to compile the servelet now but when I am trying to access means when I click on submit its showing HTTP status error.
In classpath I gave up to C:\MyProjects\beerV1\src. Please help me in solving this.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you did not defined the servlet properly in web.xml
Please post both servlet tag and servlet-mapping tag.
 
satya mahapatra
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for your reply. I did it.

My special thanks to Satou kurinosuke . You really solved my big problem. Thanks once again.And one more thing I want to tell you that, now I think I know a bit of classpath . Hope will master soon. Can you tell me from where I will get other resouces for path and classpath.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You'll plenty of info at Sun's tutorials :
http://java.sun.com/docs/books/tutorial/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic