aspose file tools*
The moose likes Servlets and the fly likes Learning Servlet code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Learning Servlet code" Watch "Learning Servlet code" New topic
Author

Learning Servlet code

Dooms James
Greenhorn

Joined: Jun 27, 2011
Posts: 4
Hello Friends

I tried compiling this code

http://www.servletworld.com/servlet-tutorials/simple-servlet-example.html, Servlet source code (WelcomeServlet.java file)

in my linux system and I am getting the following error and I can't see the problem for I copied and paste. I am a newbie and learning servlet



james@ubuntu:/usr/local/tomcat/MyProjects/Servlet-Example$ javac WelcomeServlet.java
WelcomeServlet.java:41: ')' expected
out.println("<a href="/Servlet-Example/form.html">"+"Click here to go back to input page "+"</a>");
^
WelcomeServlet.java:41: not a statement
out.println("<a href="/Servlet-Example/form.html">"+"Click here to go back to input page "+"</a>");
^
WelcomeServlet.java:41: ';' expected
out.println("<a href="/Servlet-Example/form.html">"+"Click here to go back to input page "+"</a>");
^
3 errors


I suspect I am using Linux instead of windows.

Thanks
Sawubona
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

Basic Java: your string literals aren't correctly escaping the embedded quotes.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Dooms James
Greenhorn

Joined: Jun 27, 2011
Posts: 4
THanks Bear , I will try to remove the quotes and see what happens
wang lei
Greenhorn

Joined: Mar 09, 2010
Posts: 12
hello,in my option,i think that you should use line break '\' to transfer the " signature or you can use the ' to replace the ".
try this,
out.println("<a href=\"/Servlet-Example/form.html\">"+"Click here to go back to input page "+"</a>");

good luck.

btw,i am a newbie and learning English language...
Dooms James
Greenhorn

Joined: Jun 27, 2011
Posts: 4
Wang

Thanks for your answer. I now have 13 errors for changing.

WelcomeServlet.java:6: package javax.servlet does not exist
import javax.servlet.ServletConfig;
^
WelcomeServlet.java:7: package javax.servlet does not exist
import javax.servlet.ServletException;
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

You need to include the servlet jar in your compilation classpath.
Dooms James
Greenhorn

Joined: Jun 27, 2011
Posts: 4
Thanks I did this

javac -classpath "/usr/local/Tomcat/lib/servlet-api.jar" WelcomeServlet.java

I think there is something wrong with my compiler
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Learning Servlet code