wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Head First Java 2nd ed Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head First Java 2nd ed Question" Watch "Head First Java 2nd ed Question" New topic
Author

Head First Java 2nd ed Question

Jim Moffat
Greenhorn

Joined: Sep 18, 2006
Posts: 8
Two questions:

(1) Page 629, the "KathyServlet" example,

I am getting an error on the line

out.println("
make another phrase
");

The error says

C:\Java Stuff>javac PhraseOMaticServlet.java
PhraseOMaticServlet.java:19: illegal escape character
out.println("
make another phrase</<br /> p>");
^
PhraseOMaticServlet.java:19: ')' expected
out.println("
make another phrase</<br /> p>");
^
PhraseOMaticServlet.java:19: unclosed string literal
out.println("
make another phrase</<br /> p>");

^
3 errors


Question 2:

I am running Orion and the book on pp. 625-626 implies that you can put a servlet on an anchor




But apparaently html won't come up.What should the anchor reference look like using Orion?
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8764
    
    5
let's slide this over to the Servlets forum


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Actually, I'm going to re-slide this over to Java in General (beginner) as it's not a Servlet issue per se.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

You can't embed a linefeed into a string literal.

The code should be:



with the string literal all on one line.
Jim Moffat
Greenhorn

Joined: Sep 18, 2006
Posts: 8
Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

It could also be:



or any such variation, but you can't have the opening quote on one line, and the rest of the string literal on another.
Jim Moffat
Greenhorn

Joined: Sep 18, 2006
Posts: 8
Here's a direct cut-and-paste from my code:



The only think different it appears is that the code from the book has the paragraph tags.

Here's what I get when I try to compile it:


[ September 18, 2006: Message edited by: Jim Moffat ]
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Within the String, if you want to use \ as an actual character, you must precede it with another \, because \ is the escape symbol. The compiler is telling you in this case that it doesn't recognize the escape sequences like \P.
Gail Mikels
Ranch Hand

Joined: May 07, 2001
Posts: 634
Also - need to escape the quote at the end of the path:




Gail Mikels
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

There's no backslash in the sample code.

The problem is that one of the quotes is not properly escaped.
Jim Moffat
Greenhorn

Joined: Sep 18, 2006
Posts: 8
Ahhh....that's not in the book! Thanks.

Now, as to my other question

This code is in the book



But the broswer won't bring up the HTML document. I am running Orion, so how should I code the link to the servlet class? The Cattle Drive code page showed the URL using "servlet/classname" and that didn't work either. So it is possible to link a servlet like that? The Head First book was not too clear on this.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

That's a different question which you should ask in a new post, and in the Servlets forum.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First Java 2nd ed Question
 
Similar Threads
Head First Java 2nd ed Question
Servlets from an HTML anchor
sendRedirect method
Connection Pooling
Head First Java 2nd ed Question