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

Learning Servlet code

 
Dooms James
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basic Java: your string literals aren't correctly escaping the embedded quotes.
 
Dooms James
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THanks Bear , I will try to remove the quotes and see what happens
 
wang lei
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to include the servlet jar in your compilation classpath.
 
Dooms James
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks I did this

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

I think there is something wrong with my compiler
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic