Thanks Geeta.  I am Perl,C++ web developer switching to Java and I know about
CGI etc but I did not realise that java had a special comparison method for
strings.  I was using == when I should have used String.equals("").



Kh�rt Williams
President
Williams Inter@ctive, Inc.
+1 (732) 422-1570
+1 (732) 241-8667 (Cellular)
http://www.williamsinteractive.com
[EMAIL PROTECTED]





-----Original Message-----
From:    Geeta Ramani [EMAIL PROTECTED]
Sent:    Mon, 7 Aug 2000 11:09:48 -0400
To:      [EMAIL PROTECTED]
Subject: Re: [No Subject]


Khurt:

Make sure your URL has a querystring var called "page" with value "init"... As
in
"/servlet/SimpleApp?page=init".
If you want this servlet to work via a form, make sure you write a doPost method
(with essentailly the same functionality)

If you already have taken care of the above, you should I think make the
following
test:
if (page.equals("init")) instead of the "== test that you have.

Geeta

khurt louis williams wrote:

> I wrote this very simple servlet to take one argument from the URL ( page )
and
> display the corresponding page.  However, I am having trouble with the flow
> control logic.  page== "init" always evaluates to false.  Can someone explain
to
> me what I am doing incorrectly.
> Setup is Windows NT Workstation (SP3), Apache, Apache JServ, JDK1.3, JSDK2.0
>
> The source follows:
>
> import javax.servlet.http.*;
> import javax.servlet.*;
> import java.io.*;
>
> public class SimpleApp extends HttpServlet {
>
>     public void displayPage ( PrintWriter out , String filename ) {
>         String page;
>         try {
>             RandomAccessFile inFile = new RandomAccessFile(
> "D\\web\\htdocs\\simpleApp\\" + filename,"r");
>                 while( (page = inFile.readLine()) != null ) {
>                         out.print(page);
>                 }
>                 inFile.close();
>         }
>         catch(FileNotFoundException exception) {
>                 out.println("File " + filename + " not found!");
>         }
>         catch(IOException exception) {
>                 out.println("Error opening file " + filename + " for
reading!");
>         }
>     }
>     public void doGet(HttpServletRequest request, HttpServletResponse
response)
> throws ServletException, IOException {
>         // get an PrintWriter from the response object
>         PrintWriter out = response.getWriter();
>         // prepare the response's content type
>         response.setContentType("text/html");
>         // get the page to display
>         String page = request.getParameter("page");
>
>         // print to the output stream!
>         if( (page == "init" )  || (page == "Start Over" ) ) {
>                 displayPage( out , "index.html" );
>         }
>         if( page ==  "Confirm" ) {
>                 displayPage( out, "confirm.html") ;
>         }
>         if( page == "Done" ) {
>                 displayPage( out, "done.html" );
>         }
>     }
> }
>
> Kh�rt Williams
> President
> Williams Inter@ctive, Inc.
> +1 (732) 422-1570
> +1 (732) 241-8667 (Cellular)
> http://www.williamsinteractive.com
> [EMAIL PROTECTED]
> ___________________________________________________________________________
> Visit http://www.visto.com/info, your free web-based communications center.
> Visto.com. Life on the Dot.
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html




___________________________________________________________________________
Visit http://www.visto.com/info, your free web-based communications center.
Visto.com. Life on the Dot.

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to