aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Compilation Problem in CHAP3 example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Compilation Problem in CHAP3 example" Watch "Compilation Problem in CHAP3 example" New topic
Author

Compilation Problem in CHAP3 example

satya mahapatra
Ranch Hand

Joined: Jan 07, 2006
Posts: 134
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


Regards,<br />Satya<br />SCJP,SCWCD
Manish Shah
Greenhorn

Joined: Aug 24, 2006
Posts: 20
Are you sure that the package structure is BeerExpert.BeerSelect.
I think the package structure is incorrect. Else i need to refer.


SCJP 1.2, SCWCD 1.4
satya mahapatra
Ranch Hand

Joined: Jan 07, 2006
Posts: 134
I checked it. Its correct only.
Imran Vohra
Ranch Hand

Joined: Dec 12, 2005
Posts: 77

Did you import your model class in servlet?

Thanks
Imran
satya mahapatra
Ranch Hand

Joined: Jan 07, 2006
Posts: 134
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

Joined: Jan 07, 2006
Posts: 134
Friends I m using JDK1.5. Is that the problem???
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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


[My Blog]
All roads lead to JavaRanch
satya mahapatra
Ranch Hand

Joined: Jan 07, 2006
Posts: 134
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

Maybe you did not defined the servlet properly in web.xml
Please post both servlet tag and servlet-mapping tag.
satya mahapatra
Ranch Hand

Joined: Jan 07, 2006
Posts: 134
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

Joined: Nov 24, 2005
Posts: 14687
    
  16


You'll plenty of info at Sun's tutorials :
http://java.sun.com/docs/books/tutorial/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compilation Problem in CHAP3 example
 
Similar Threads
problem using javac with -classpath option
help for HFSJ - CH 3 Page 84
Having Problem Compiling Servlet Code "Hands on MVC"
HF Servlet and Java - MVC tutorial
help for HFSJ - CH 3 Page 84