• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with 1st example in book Head First servlets and jsp

 
Krystian Kowalski
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello , i am having some problems with 1st example in book. I have done some researches but i haven't found how to solve my problem. When i try to compile that, i get some errors and i don't know what to do



The name of class etc is in Polish language, i hope that is ok for you : P
When i try to compile that with "javac WyborPiwa.java" i get this:

C:\Users\qwerty>cd..

C:\Users>cd ..

C:\>javac WyborPiwa.class
javac: invalid flag: WyborPiwa.class
Usage: javac <options> <source files>
use -help for a list of possible options

C:\>javac WyborPiwa.class
javac: invalid flag: WyborPiwa.class
Usage: javac <options> <source files>
use -help for a list of possible options

C:\>javac WyborPiwa.java
WyborPiwa.java:9: error: illegal character: \8220
response.setContentType(“text/html”);
^
WyborPiwa.java:9: error: ';' expected
response.setContentType(“text/html”);
^
WyborPiwa.java:9: error: illegal start of expression
response.setContentType(“text/html”);
^
WyborPiwa.java:9: error: illegal character: \8221
response.setContentType(“text/html”);
^
WyborPiwa.java:11: error: illegal character: \8220
out.println(“Porada piwna<br>”);
^
WyborPiwa.java:11: error: ';' expected
out.println(“Porada piwna<br>”);
^
WyborPiwa.java:11: error: illegal character: \8221
out.println(“Porada piwna<br>”);
^
WyborPiwa.java:11: error: not a statement
out.println(“Porada piwna<br>”);
^
WyborPiwa.java:12: error: illegal character: \8220
String c = request.getParameter(“kolor”);
^
WyborPiwa.java:12: error: ';' expected
String c = request.getParameter(“kolor”);
^
WyborPiwa.java:12: error: illegal character: \8221
String c = request.getParameter(“kolor”);
^
WyborPiwa.java:12: error: ';' expected
String c = request.getParameter(“kolor”);
^
WyborPiwa.java:13: error: illegal character: \8220
out.println(“<br>Wybrany kolor piwa: “ + c);
^
WyborPiwa.java:13: error: not a statement
out.println(“<br>Wybrany kolor piwa: “ + c);
^
WyborPiwa.java:13: error: ';' expected
out.println(“<br>Wybrany kolor piwa: “ + c);
^
WyborPiwa.java:13: error: ';' expected
out.println(“<br>Wybrany kolor piwa: “ + c);
^
WyborPiwa.java:13: error: illegal character: \8220
out.println(“<br>Wybrany kolor piwa: “ + c);
^
WyborPiwa.java:13: error: not a statement
out.println(“<br>Wybrany kolor piwa: “ + c);
^
WyborPiwa.java:13: error: ';' expected
out.println(“<br>Wybrany kolor piwa: “ + c);
^
19 errors



The directory of WyborPiwa.class is in C:\WyborPiwa.class
I have already done the xml and html and it's working (moved them to the right folders ;) )
Please help

 
bharat salunkhe
Greenhorn
Posts: 25
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Krystian Kowalski wrote:Hello , i am having some problems with 1st example in book. I have done some researches but i haven't found how to solve my problem. When i try to compile that, i get some errors and i don't know what to do



The name of class etc is in Polish language, i hope that is ok for you : P
When i try to compile that with "javac WyborPiwa.java" i get this:

C:\Users\qwerty>cd..

C:\Users>cd ..

C:\>javac WyborPiwa.class
javac: invalid flag: WyborPiwa.class
Usage: javac <options> <source files>
use -help for a list of possible options

C:\>javac WyborPiwa.class
javac: invalid flag: WyborPiwa.class
Usage: javac <options> <source files>
use -help for a list of possible options

C:\>javac WyborPiwa.java
WyborPiwa.java:9: error: illegal character: \8220
response.setContentType(“text/html”);
^
WyborPiwa.java:9: error: ';' expected
response.setContentType(“text/html”);
^
WyborPiwa.java:9: error: illegal start of expression
response.setContentType(“text/html”);
^
WyborPiwa.java:9: error: illegal character: \8221
response.setContentType(“text/html”);
^
WyborPiwa.java:11: error: illegal character: \8220
out.println(“Porada piwna<br>”);
^
WyborPiwa.java:11: error: ';' expected
out.println(“Porada piwna<br>”);
^
WyborPiwa.java:11: error: illegal character: \8221
out.println(“Porada piwna<br>”);
^
WyborPiwa.java:11: error: not a statement
out.println(“Porada piwna<br>”);
^
WyborPiwa.java:12: error: illegal character: \8220
String c = request.getParameter(“kolor”);
^
WyborPiwa.java:12: error: ';' expected
String c = request.getParameter(“kolor”);
^
WyborPiwa.java:12: error: illegal character: \8221
String c = request.getParameter(“kolor”);
^
WyborPiwa.java:12: error: ';' expected
String c = request.getParameter(“kolor”);
^
WyborPiwa.java:13: error: illegal character: \8220
out.println(“<br>Wybrany kolor piwa: “ + c);
^
WyborPiwa.java:13: error: not a statement
out.println(“<br>Wybrany kolor piwa: “ + c);
^
WyborPiwa.java:13: error: ';' expected
out.println(“<br>Wybrany kolor piwa: “ + c);
^
WyborPiwa.java:13: error: ';' expected
out.println(“<br>Wybrany kolor piwa: “ + c);
^
WyborPiwa.java:13: error: illegal character: \8220
out.println(“<br>Wybrany kolor piwa: “ + c);
^
WyborPiwa.java:13: error: not a statement
out.println(“<br>Wybrany kolor piwa: “ + c);
^
WyborPiwa.java:13: error: ';' expected
out.println(“<br>Wybrany kolor piwa: “ + c);
^
19 errors



The directory of WyborPiwa.class is in C:\WyborPiwa.class
I have already done the xml and html and it's working (moved them to the right folders ;) )
Please help






hi
Krystian did you copy and pest this programe..
if yes then just delete this sign " and write again..
i thing nothing any wrong in this servlet..
 
Krystian Kowalski
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried to compile with : javac WyborPiwa.java , didin't typed " " . Is it working for you ?
 
Krystian Kowalski
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried to do something in eclipse but i think i just make those things harder for me and now i have completly idead what am i doing ... ;p Can someone help me ?

Here is my html website named form.html:


Here is my web.xml :



And my servlet WyborPiwa.java :



Now i really don't know how to setup this , how to compile etc.. i was trying to use directions from book
 
Krystian Kowalski
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying really hard from the morning and nothing ;p Here i sent my eclipse files , mby it would be easier for you guys to check out everything. I really appreciate any help.
I can't add any zip or rar to attachments so i used sendspace :
http://www.sendspace.com/file/8d9p4x
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ditch Eclipse if it only serves to confuse you.
The problem with your first try, compiling the .java file with javac from the command-line, has to do with the illegal characters you use to quote your String literals.
Those seem to be Unicode left double quotation mark (U+201C) and right double quotation mark (U+201D), instead of the required good old ASCII compatible quotation mark (U+0022).
This is probably down to your computers regional settings, which leads to those characters being inserted when you hit the " button on your keyboard.
 
Krystian Kowalski
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried to compile that ( " -signs are changed):


with using : javac WyborPiwa.java and that's what i get:

C:\Users\qwerty>cd ..

C:\Users>cd ..

C:\>javac WyborPiwa.java
WyborPiwa.java:3: error: package javax.servlet does not exist
import javax.servlet.*;
^
WyborPiwa.java:4: error: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
WyborPiwa.java:7: error: cannot find symbol
public class WyborPiwa extends HttpServlet {
^
symbol: class HttpServlet
WyborPiwa.java:8: error: cannot find symbol
public void doPost(HttpServletRequest request, HttpServletResponse respo
nse)
^
symbol: class HttpServletRequest
location: class WyborPiwa
WyborPiwa.java:8: error: cannot find symbol
public void doPost(HttpServletRequest request, HttpServletResponse respo
nse)
^
symbol: class HttpServletResponse
location: class WyborPiwa
WyborPiwa.java:9: error: cannot find symbol
throws IOException, ServletException {
^
symbol: class ServletException
location: class WyborPiwa
6 errors

C:\>


I know about error package because -it doesn't exist but i don't really know what else i should change and how
I have done head first java, and i was familliar with eclipse but now i am confused ;/
 
bharat salunkhe
Greenhorn
Posts: 25
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Krystian...



package com.example.web;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class WyborPiwa extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Porada piwna<br>");
String c = request.getParameter("kolor");
out.println("<br>Wybrany kolor piwa:" + c);
}
}





check this it will work fine.. just change doPost to doGet
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Krystian Kowalski wrote:I have tried to compile that ( " -signs are changed):

...


with using : javac WyborPiwa.java and that's what i get:

...

6 errors


Seems like the compiler can't find the Servlet API's JAR file.
The Servlet API classes aren't part of the standard JDK. Your best bet would be to look in the lib folder of your servlet container (presumably Tomcat) and get the servlet-api.jar for there.
Then add that JAr file to your buildpath in Eclipse or the classpath on the commandline invocation of javac, and the compiler warnings should disappear.
 
Krystian Kowalski
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
everything is fine i didin't make jar, i just remade a setup of servers and it's working. I was using eclipse. I was sure that setup is fine
 
Ivan Jozsef Balazs
Rancher
Posts: 992
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



No problem!

Does it happen to mean "choice of beer"?



 
Krystian Kowalski
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!