Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Head First Java 2nd ed Question

 
Jim Moffat
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
let's slide this over to the Servlets forum
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, I'm going to re-slide this over to Java in General (beginner) as it's not a Servlet issue per se.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Schlentz
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also - need to escape the quote at the end of the path:


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no backslash in the sample code.

The problem is that one of the quotes is not properly escaped.
 
Jim Moffat
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a different question which you should ask in a new post, and in the Servlets forum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic