Hi Ralf!

Your html file seems to send the following parameters to your servlet:
        cos= one of AI, MI, TI, WI, according to your selection
        what = tplan (* always tplan, never lplan *)

Check it by setting FORM method = "GET" as following:
        <FORM ACTION="http://onyx:8080/wdbserv/dispatcher.main" METHOD="GET">

When you click 'Abfrage starten' button, the location (or address) 
field in web browser shows the paratmers sent to the servlet just like
following:
        http://onyx:8080/wdbserv/dispatcher.main?cos=WI&what=tplan

Therefore, your doGetOrPost function in servlet code always calls
doTest(req.getParameter("cos")). And doTest function always println
"doTest: cos" because you send "cos" string, not cos parameter
as argument to doTest function.

I didn't run your code actually. So my thought may be wrong.
Please check by yourself and I'll appreciate if you notify the result.

Good luck!


Ralf Weidemann wrote:
> 
> >>>>> On Fri, 12 Mar 1999 09:27:00 +0900, Sung-Gwan Heo <[EMAIL PROTECTED]> said:
> 
>   Sung-Gwan> Ralf Weidemann wrote:
>   >>  I get only one time the right output from my servlet then it
>   >> shows every time the same until I touch (or recompile) the class
>   >> file. It get called over a FORM via POST. It should show up
>   >> something different (depends on what I choosed in the OPTION
>   >> menu). Why it will only show up the right after I touch the class
>   >> ?  What's the problem here ??
> 
>   Sung-Gwan> Servlets are loaded when web server begins.  So, try to
>   Sung-Gwan> shutdow web server and restart it.
> 
>   Sung-Gwan>    $ apachectl stop $ apachectl restart
> 
> No, that's not the problem. Below you could see the source
> of the servlet and of the html page that calls the servlet
> and I get exact one time the right output and then if I make
> a new choose I get every time the output from the first choose
> until I touch the class file so that it get loaded again
> from jserv. I'm new to this and I have no clue why this
> happens..
> 
> Ralf
> 
> <HTML>
>   <HEAD>
>   </HEAD>
>   <BODY>
>         <FORM ACTION="http://onyx:8080/wdbserv/dispatcher.main" METHOD="POST">
>           Studiengang: <P>
>                 <SELECT NAME="cos">
>                   <OPTION VALUE="AI"> AI
>                   <OPTION VALUE="MI"> MI
>                   <OPTION VALUE="TI"> TI
>                   <OPTION VALUE="WI"> WI
>                 </SELECT>
>           <P>
>                 <BR>
>           <P>
>                 <BR>
>           <P>
>                 <INPUT TYPE="hidden" NAME="what" VALUE="tplan">
>                 <INPUT TYPE="submit" VALUE="Abfrage starten">
>         </FORM>
>         <P>
>           <BR>
>         <P>
>           <BR>
>         <P>
>         </FORM>
>   </BODY>
> </HTML>
> 
> import java.io.*;
> import java.net.*;
> import java.sql.*;
> import java.util.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> 
> public class main extends HttpServlet
> {
>   static private Connection con = null;
>   static private Statement stmt = null;
> 
>   String url  = "jdbc:postgresql://onyx/test";
>   String user = "test";
>   String pass = "test";
> 
>   ByteArrayOutputStream bs = new ByteArrayOutputStream(100000);
>   PrintWriter out = new PrintWriter(new OutputStreamWriter(bs));
> 
>   public void init(ServletConfig config) throws ServletException
>   {
>     String driver = "postgresql.Driver";
>     try
>     {
>       Class.forName(driver);
>       System.err.println(this.toString()
>                          + ": jdbc driver "
>                          + driver + " loaded");
>     }
>     catch(ClassNotFoundException e)
>     {
>       System.err.println(this.toString()
>                          + ": jdbc driver "
>                          + driver + " not loaded");
>       e.printStackTrace(System.err) ;
>     }
>     super.init(config);
>   }
> 
>   public String getServletInfo()
>   {
>     return "WDB-DISPATCHER";
>   }
> 
>   /**
>    * <p>Do GET-Requests</p>
>    */
>   public void doGet (HttpServletRequest req,
>                      HttpServletResponse res)
>     throws ServletException, IOException
>   {
>     doGetOrPost (req, res);
>   }
> 
>   /**
>    * <p>Do POST-Requests</p>
>    */
>   public void doPost (HttpServletRequest req,
>                       HttpServletResponse res)
>     throws ServletException, IOException
>   {
>     doGetOrPost (req, res);
>   }
> 
>   /**
>    * <p>GET/POST-Requests work the same..</p>
>    */
>   private void doGetOrPost (HttpServletRequest req,
>                             HttpServletResponse res)
>     throws ServletException, IOException
>   {
>     try
>     {
>       if (con == null || con.isClosed())
>       {
>         con = DriverManager.getConnection(url, user, pass);
>       }
>     }
>     catch (Exception ex)
>     {
>       out.println("<PRE>");
>       out.println(ex.getMessage());
>       ex.printStackTrace(out);
>       out.println("</PRE>");
>       try
>       {
>         con.close();
>       }
>       catch (Exception ex2)
>       {
>       }
>       con = null;
>       stmt = null;
>     }
> 
>     String what = req.getParameter("what");
>     try
>     {
>       if (what.equals("tplan"))
>       {
>         doTest(req.getParameter("cos"));
>       }
>       else if (what.equals("lplan"))
>       {
>         doLesson(req.getParameter("cos"),
>                  req.getParameter("sem"));
>       }
>       else
>       {
>         out.println("<PRE>wdbserv error: unknown 'what'");
>       }
>     }
>     catch (Exception ex)
>     {
>       out.println("<PRE>");
>       out.println(ex.getMessage());
>       ex.printStackTrace(out);
>       out.println("</PRE>");
>     }
> 
>     /* that's the end my friend */
>     out.close();
>     res.setContentType("text/html");
>     res.setContentLength(bs.size());
>     bs.writeTo(res.getOutputStream());
>   }
> 
>   void doTest (String cos)
>   {
>     out.println("<HTML>");
>     out.println("doTest: ");
>     out.println(cos);
>     out.println("</HTML>");
>   }
> 
>   void doLesson (String cos, String sem)
>   {
>     out.println("<HTML>");
>     out.println("doLesson: ");
>     out.println(cos + sem);
>     out.println("</HTML>");
>   }
> }


-- 
Heo, Sung-Gwan                    

Software Engineer                 mailto:[EMAIL PROTECTED]
R&D Center                        phone:+82-415-861-3887 
Turbo-Tek Co., Ltd.               http://www.turbotek.co.kr


----------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://www.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to