| Author |
Head first servlets and JSP - Hands on MVC exercise - help!
|
Matt Richardson
Greenhorn
Joined: Oct 07, 2004
Posts: 4
|
|
Hi there, I'm trying to work through Head First Servlets and JSP but I'm stuck on the hands-on MVC exercise in chapter 3. I'm trying to compile the first version of the controller servlet using javac. I have set up the classpath correctly but the servlet is failing with syntax errors. I am unable to see all of these, because they are scrolling off the top of my msdos command window (I know, I should probably use Linux), but it looks rather like the problems start with the import statements. I suspect that the servlet-api.jar file is not being found. The javac command I am using is javac -classpath C:\tomcat\common\lib\servlet-api.jar:classes:. -d classes src\com\example\web\BeerSelect.java I'm sure the path is right I have also tried - which is what the jar file looks like under a msdos dir command: javac -classpath C:\tomcat\common\lib\SERVLE~1.JAR:classes:. -d classes src\com\example\web\BeerSelect.java I can see my servlet-api.jar file under this directory My source code file is as follows (in case there is actually something wrong with that) package com.example.web; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class BeerSelect 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); } } Please can anyone help otherwise I risk getting certified in an entirely different sense? Thanks, Matt
|
 |
Matt Richardson
Greenhorn
Joined: Oct 07, 2004
Posts: 4
|
|
I think I've managed to compile my servlet - I used the command javac -classpath C:\tomcat\common\lib\servlet-api.jar -d classes C:\Matt\Java\projects\beerv1\src\com\example\web\BeerSelect.java and took out the ':classes:.' part after servlet-api.jar that was in the book - presumably that must be some unix/linux specific syntax? Thanks
|
 |
M Rama
Ranch Hand
Joined: Mar 04, 2005
Posts: 88
|
|
Your class path should've been the following: javac -classpath C:/Tomcat5.5/common/lib/servlet-api.jar;classes;. -d classes src/com/example/web/BeerSelect.java you got colons instead of semicolons...
|
 |
Matt Richardson
Greenhorn
Joined: Oct 07, 2004
Posts: 4
|
|
Thanks for your help - this is in error in the 2004 version of the book (not sure whether this is the latest edition). Regards, Matt
|
 |
 |
|
|
subject: Head first servlets and JSP - Hands on MVC exercise - help!
|
|
|