• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Learning Servlet code

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THanks Bear , I will try to remove the quotes and see what happens
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic