• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot compile servlets

 
gong pex
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I had tried to compile simple servlet code that I got from read Head First servlet and JSP, using command prompt, but it still failed.

I don't know where I must begin but this that I can give look for you all:



I don't know what't the mean of your path, whether is a D:\project1?,

and the result on command prompt are like this:



I had tried to manual compile like this :



and the results are like this:

D:\project1\src>javac Ch1Servlet.java
Ch1Servlet.java:11: error: illegal character: \8220
out.println(ô<html> ô +
^
Ch1Servlet.java:11: error: illegal character: \8220
out.println(ô<html> ô +
^
Ch1Servlet.java:11: error: not a statement
out.println(ô<html> ô +
^
Ch1Servlet.java:12: error: illegal character: \8220
ô
^
Ch1Servlet.java:11: error: not a statement
out.println(ô<html> ô +
^
Ch1Servlet.java:13: error: illegal character: \8221
<body>ö +
^
Ch1Servlet.java:14: error: illegal character: \8220
ô
^
Ch1Servlet.java:13: error: not a statement
<body>ö +
^
Ch1Servlet.java:15: error: > expected
<h1 align=center>HF\Æs Chapter1 Servlet</h1>ö +
^
Ch1Servlet.java:15: error: illegal start of expression
<h1 align=center>HF\Æs Chapter1 Servlet</h1>ö +
^
Ch1Servlet.java:15: error: illegal character: \92
<h1 align=center>HF\Æs Chapter1 Servlet</h1>ö +
^
Ch1Servlet.java:15: error: illegal character: \8217
<h1 align=center>HF\Æs Chapter1 Servlet</h1>ö +
^
Ch1Servlet.java:15: error: ';' expected
<h1 align=center>HF\Æs Chapter1 Servlet</h1>ö +
^
Ch1Servlet.java:15: error: illegal start of type
<h1 align=center>HF\Æs Chapter1 Servlet</h1>ö +
^
Ch1Servlet.java:15: error: ';' expected
<h1 align=center>HF\Æs Chapter1 Servlet</h1>ö +
^
Ch1Servlet.java:15: error: illegal character: \8221
<h1 align=center>HF\Æs Chapter1 Servlet</h1>ö +
^
Ch1Servlet.java:17: error: illegal character: \8220
ô<br>ö + today + ô</body>ö + ô</html>ö);
^
Ch1Servlet.java:17: error: illegal character: \8221
ô<br>ö + today + ô</body>ö + ô</html>ö);
^
Ch1Servlet.java:17: error: illegal character: \8220
ô<br>ö + today + ô</body>ö + ô</html>ö);
^
Ch1Servlet.java:17: error: not a statement
ô<br>ö + today + ô</body>ö + ô</html>ö);
^
Ch1Servlet.java:17: error: illegal start of type
ô<br>ö + today + ô</body>ö + ô</html>ö);
^
Ch1Servlet.java:17: error: illegal start of expression
ô<br>ö + today + ô</body>ö + ô</html>ö);
^
Ch1Servlet.java:17: error: illegal character: \8221
ô<br>ö + today + ô</body>ö + ô</html>ö);
^
Ch1Servlet.java:17: error: not a statement
ô<br>ö + today + ô</body>ö + ô</html>ö);
^
Ch1Servlet.java:17: error: illegal character: \8220
ô<br>ö + today + ô</body>ö + ô</html>ö);
^
Ch1Servlet.java:17: error: not a statement
ô<br>ö + today + ô</body>ö + ô</html>ö);
^
Ch1Servlet.java:17: error: illegal start of type
ô<br>ö + today + ô</body>ö + ô</html>ö);
^
Ch1Servlet.java:17: error: illegal start of expression
ô<br>ö + today + ô</body>ö + ô</html>ö);
^
Ch1Servlet.java:17: error: illegal character: \8221
ô<br>ö + today + ô</body>ö + ô</html>ö);
^
Ch1Servlet.java:17: error: not a statement
ô<br>ö + today + ô</body>ö + ô</html>ö);
^
Ch1Servlet.java:17: error: illegal start of expression
ô<br>ö + today + ô</body>ö + ô</html>ö);
^
31 errors


someone, please help me,

about specification of my file, are like this:

- my apache is apache tomcat 7.0.23

- my file stored in D:\project1\src\Ch1Servlet.java
and the web.xml stored in D:\project1\etc\web.xml

Thank you


 
Suraj Jadhav
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all it looks like there are compilation error in your code. You first need to resolve those error. Did you copied the html contains from some editors. Because compiler is saying that there are special characters in your code. I will suggest rather that use IDE like Eclipse rather than plain notepad if you are new to Java. IDE will point out the common error before compiling.

Second problem that you are getting is while compiling your code.



First make sure that you have set JAVA_HOME properly. Also servlet jar are in classpath. I could see that you have given wrong path.



It should be d:/project1/tomcat/common/lib/ where / should be after d:

Head First servlet and JSP is a great book. Compilation details that are given in first chapter is related to Mac OS and I guess you are using Windows. You need to make little changes in command while compiling your code.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you using to create the Java files? Is it Word or WordPad?
 
gong pex
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:What are you using to create the Java files? Is it Word or WordPad?


I create the java file using notepad
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whatever it is, it's using the wrong character(s) for quote characters. I'd suggest using an editor that's specifically geared towards code.
 
gong pex
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no, that impossible

Because I copy and paste that code from java book (Head First Servlet and JSP 2nd edition)

from page: 30-31(Chapter 1)

please answer me

thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gong pex wrote:no, that impossible

You can either argue, or you can make progress.

Hell must have frozen over because this:
D:\project1\src>javac Ch1Servlet.java
Ch1Servlet.java:11: error: illegal character: \8220
out.println(ô<html> ô +

says that the impossible has happened.
 
gong pex
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can either argue, or you can make progress.

Hell must have frozen over because this: says that the impossible has happened.


about this, don't be angry sir,

I just astonished because book like oreilly can be mistaken to write the servlets.

This servlet that I got from Oreilly (head servlet and jsp) Ch1Servlet.java on attachment

I deliberately print screen because when I copy paste on code here, it there is some disturbance.
servlet.png
[Thumbnail for servlet.png]
image code
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has nothing to do with the book, but with the tools that you are using. Something along the way is turning the normal quotes into invalid characters.
 
gong pex
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tools like:

- notepad ++

- wordpad and ms office

so,what's tool that can I use to build servlets (if from these tool can't be use, I'll downloaded other)?
 
Rob Spoor
Sheriff
Pie
Posts: 20559
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use Notepad++. WordPad and MS Word often don't use " and ' for quotes but replace these with better looking alternatives. While that's OK for pieces of text, it's a nightmare for pieces of code.
 
Kuldip Shetty
Ranch Hand
Posts: 43
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As updated in above threads the issue is related to quotes. Similar question has been answered and resolved in another post - Click here
 
Kumaravadivel Subramani
Ranch Hand
Posts: 171
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using Notepad++, you have an option to display all characters in your current document. (View-> Show all Characters) This will help you to check what are the special characters are available in document. As mentioned above some of the tools does inserting of special characters.
 
gong pex
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

First make sure that you have set JAVA_HOME properly. Also servlet jar are in classpath. I could see that you have given wrong path.



It should be d:/project1/tomcat/common/lib/ where / should be after d:

Head First servlet and JSP is a great book. Compilation details that are given in first chapter is related to Mac OS and I guess you are using Windows. You need to make little changes in command while compiling your code.



about JAVA_HOME, Is it like this ?

(on attachment : JAVA_HOME.png)

I have use notepad ++ and display all characters (View->Show all Characters) and this the image :

(on attachment : ntp++.png)

In book JSP (Head Servlet and JSP) I think it using JVM,

please told me how to type in command prompt fully. Because I really confused

because the results still same

thanks (please help me.....)
JAVA_HOME.png
[Thumbnail for JAVA_HOME.png]
JAVA_HOME.png
ntp++.png
[Thumbnail for ntp++.png]
ntp++.png
 
Rob Spoor
Sheriff
Pie
Posts: 20559
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Replace all your double quotes. The wrong ones have already been stored in your file.
 
gong pex
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, double quotes where? (in ntpad ++ or JAVA_HOME)?

replace with what?

please answer

thanks
 
Noor Donur
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dear,

Take a deep breath and relax.

Have a glance, concentrate and try to analyze the suggestions.

Please don't be in hurry.

If you make this a practice you can understand, work easily and can teach yourself.

 
Rob Spoor
Sheriff
Pie
Posts: 20559
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gong pex wrote:Sorry, double quotes where? (in ntpad ++ or JAVA_HOME)?

replace with what?

please answer

thanks

In Notepad++, replace all occurrences of ‘ and ’ with ', and “ and ” with ". See also http://jhy.io/tools/convert-word-to-plain-text
 
gong pex
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Notepad++, replace all occurrences of ‘ and ’ with ', and “ and ” with ". See also http://jhy.io/tools/convert-word-to-plain-text


I had change it like this : (on attachment ntp++_ch)

and then I compile it using 'javac' in command prompt and the result: (on attachment cmd)

about classpath on environment variable, whether my path is correct? (on attachment classpath)

please be patient to teach me, because I still very newbie to learn servlet and JSP

Thank you
ntp++_ch.png
[Thumbnail for ntp++_ch.png]
ntp++_ch
cmd.png
[Thumbnail for cmd.png]
cmd
classpath.png
[Thumbnail for classpath.png]
classpath
 
Kumaravadivel Subramani
Ranch Hand
Posts: 171
Java Linux Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey gong pex, don't be hurry to solve the problem. Analysis the problem and understand what causes it. Seems your special character problem have solved. After seeing your attachments I suggest you to do the following things:

* In your Ch1Servlet.java, println function have extra unary character "+" at line number 14. Remove this either in end of line 13th or in 14.
* To compile Servlets you need to have "servlet-api.jar" in your classpath. If you have any web/app server, it should there in lib folder.

Follow the habit of analyzing the compilation error, it will be good for you to learn more.
 
gong pex
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your Ch1Servlet.java, println function have extra unary character "+" at line number 14. Remove this either in end of line 13th or in 14.


yeah you right, there is excess + sign in my file.

To compile Servlets you need to have "servlet-api.jar" in your classpath. If you have any web/app server, it should there in lib folder.


I never compile using servlet-api.jar, can you tell me (in command prompt) at least give me an example.

please be patient to teach me.

Thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic