my dog learned polymorphism*
The moose likes Servlets and the fly likes cannot compile servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "cannot compile servlets" Watch "cannot compile servlets" New topic
Author

cannot compile servlets

gong pex
Ranch Hand

Joined: Oct 27, 2011
Posts: 41
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

Joined: Mar 10, 2010
Posts: 25
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

Joined: Jan 10, 2002
Posts: 60810
    
  65

What are you using to create the Java files? Is it Word or WordPad?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
gong pex
Ranch Hand

Joined: Oct 27, 2011
Posts: 41
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

Joined: Jan 10, 2002
Posts: 60810
    
  65

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

Joined: Oct 27, 2011
Posts: 41
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

Joined: Jan 10, 2002
Posts: 60810
    
  65

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

Joined: Oct 27, 2011
Posts: 41
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.



[Thumbnail for servlet.png]

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

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

Joined: Oct 27, 2011
Posts: 41
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

Joined: Oct 27, 2005
Posts: 19656
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Kuldip Shetty
Ranch Hand

Joined: Jan 07, 2010
Posts: 39

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

Joined: Jul 05, 2008
Posts: 166

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.


No pain, No gain.
OCJP 1.6
gong pex
Ranch Hand

Joined: Oct 27, 2011
Posts: 41

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.....)



[Thumbnail for JAVA_HOME.png]


[Thumbnail for ntp++.png]

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

Replace all your double quotes. The wrong ones have already been stored in your file.
gong pex
Ranch Hand

Joined: Oct 27, 2011
Posts: 41
Sorry, double quotes where? (in ntpad ++ or JAVA_HOME)?

replace with what?

please answer

thanks
Noor Donur
Greenhorn

Joined: Dec 13, 2011
Posts: 6

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.


Thanks,
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

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

Joined: Oct 27, 2011
Posts: 41
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



[Thumbnail for ntp++_ch.png]


[Thumbnail for cmd.png]


[Thumbnail for classpath.png]

Kumaravadivel Subramani
Ranch Hand

Joined: Jul 05, 2008
Posts: 166

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

Joined: Oct 27, 2011
Posts: 41
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: cannot compile servlets
 
Similar Threads
Headfirst Servlets & JSP
Unable to compile servlet
compiling Servlet Example in HF Servlets & JSP
Servelts Error from Head First Servlets & JSP
classpath help with examples