Hi Chris ,
But you did not show us the body of the servlet "LiveLinks" which is i
suppose the action associeted to
the Post FORM , Since our major problem resides in that action (i mean
Servlet mentionned as action=....)
Note that i can invoke it individualy , but not from the Servlet that define
the POST FORM
And in your example there are some lines like file://name
what is their purpose exactly . Are they mendatory for "Livelinks" to work ?
If can you please give more detail on their use
Many thanks .
Sidaty [EMAIL PROTECTED]
----- Message d'origine -----
De : Chris Pratt <[EMAIL PROTECTED]>
A : <[EMAIL PROTECTED]>
Envoy� : vendredi 17 septembre 1999 18:27
Objet : Re: Stil having Problem with POST FORM
> Below is a simple HTML Link manager that I wrote when I was learning
> servlets. If a GET request comes in it displays the links it has
collected.
> If a POST request comes in, it expects to receive the information to add
> another link to it's list of remembered links. Pretty simplistic, but
> different behavior between the get and post sides. It's not the most
> efficient beast, but it's a pretty good example program.
> (*Chris*)
>
> /**
> * Links - Servlet to maintain a list of links
> *
> * @author Chris Pratt
> * @version 1.0
> *
> * Properties
> * dbDriver oracle.jdbc.driver.OracleDriver
> * database jdbc:oracle:thin:@localhost:1521:ORCL
> * user User
> * pwd Password
> * table science
> * title Fun with Science!
> *
> * 8/24/1998
> */
> import java.io.*;
> import java.sql.*;
> import java.text.*;
> import java.util.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class Links extends HttpServlet {
> protected String conString;
> protected String conUser;
> protected String conPwd;
> protected String table;
> protected String title;
>
> public void init (ServletConfig cfg) throws ServletException {
> super.init(cfg);
> try {
> Class.forName(cfg.getInitParameter("dbDriver"));
> } catch(ClassNotFoundException cx) {
> throw new ServletException("Can't load Database Driver [" +
> cx.getMessage() + "]");
> }
> conString = cfg.getInitParameter("database");
> conUser = cfg.getInitParameter("user");
> conPwd = cfg.getInitParameter("pwd");
> table = cfg.getInitParameter("table");
> title = cfg.getInitParameter("title");
> } file://init
>
> public void doGet (HttpServletRequest req,HttpServletResponse res)
throws
> ServletException, IOException {
> try {
> Connection c =
DriverManager.getConnection(conString,conUser,conPwd);
> Statement s = c.createStatement();
> Object[] args = {table};
> String query = MessageFormat.format("SELECT * FROM {0}",args);
> ResultSet rs = s.executeQuery(query);
> ServletOutputStream out = res.getOutputStream();
> // set content type and other response header fields first
> res.setContentType("text/html");
> // then write the data of the response
> out.println("<HTML>");
> out.println(" <HEAD>");
> if(title != null) {
> out.println(" <TITLE>" + title + "</TITLE>");
> } else {
> out.println(" <TITLE>Live Links!</TITLE>");
> }
> out.println(" </HEAD>");
> out.println(" <BODY>");
> if(title != null) {
> out.println(" <H1>" + title + "</H1>");
> out.println(" <HR><BR>");
> }
> while(rs.next()) {
> out.println(" <A HREF=" + rs.getString("ADDRESS") + ">" +
> rs.getString("DESCRIPTION") + "</A><BR>");
> }
> out.println(" <HR><BR>");
> out.println(" <P>Add your own link");
> out.println(" <FORM ACTION=\"/servlet/LiveLinks\"
> METHOD=\"Post\">");
> out.println(" <P>Description <INPUT TYPE=\"Text\"
> NAME=\"Description\"><BR>");
> out.println(" <P>Address <INPUT TYPE=\"Text\"
> NAME=\"Address\"><BR>");
> out.println(" <P><INPUT TYPE=\"Submit\" VALUE=\"Submit\">");
> out.println(" <INPUT TYPE=\"Reset\" VALUE=\"Clear\"><BR>");
> out.println(" </FORM>");
> out.println(" <ADDRESS><A
> HREF=\"mailto:[EMAIL PROTECTED]\">Chris Pratt:
> WebMaster</A></ADDRESS>");
> out.println(" </BODY>");
> out.println("</HTML>");
> out.close();
> c.close();
> } catch(SQLException sx) {
> ServletOutputStream err = res.getOutputStream();
> res.setContentType("text/html");
> err.println("<HTML>\n <HEAD>\n <TITLE>Live Links - SQL
> Exception</TITLE>\n </HEAD>\n <BODY>");
> err.println(" <P>An SQL Exception Occurred while processing the
> request [" + sx.getMessage() + "]");
> err.println(" <UL>");
> err.println(" <LI>conString = " + conString);
> err.println(" <LI>conUser = " + conUser);
> err.println(" <LI>conPwd = " + conPwd);
> err.println(" <LI>table = " + table);
> err.println(" </UL>");
> err.println(" </BODY>\n</HTML>");
> err.close();
> }
> } file://doget
>
> public void doPost (HttpServletRequest req,HttpServletResponse res)
throws
> ServletException, IOException {
> String query = null;
> try {
> ServletOutputStream out = res.getOutputStream();
> res.setContentType("text/html");
> Connection c =
DriverManager.getConnection(conString,conUser,conPwd);
> Statement s = c.createStatement();
> Object[] args =
>
{table,req.getParameterValues("Description")[0],req.getParameterValues("Addr
> ess")[0]};
> query = MessageFormat.format("INSERT INTO {0} VALUES(''{2}'',
> ''{1}'')",args);
> out.println("<HTML>");
> out.println(" <HEAD>");
> if(s.executeUpdate(query) > 0) {
> out.println(" <TITLE>Update Accepted</TITLE>");
> out.println(" </HEAD>");
> out.println(" <BODY>");
> out.println(" <P>Thank you for contributing to the list.");
> out.println(" <P><A HREF=\"/servlet/LiveLinks\">Return to the
> list</A>");
> } else {
> out.println(" <TITLE>Update Failed</TITLE>");
> out.println(" </HEAD>");
> out.println(" <BODY>");
> out.println(" <P>I'm sorry, for some reason your update did not
> work, please contact the webmaster.");
> out.println(" <P><A HREF=\"/servlet/LiveLinks\">Return to the
> list</A>");
> }
> out.println(" <ADDRESS><A
> HREF=\"mailto:[EMAIL PROTECTED]\">Chris Pratt:
> WebMaster</A></ADDRESS>");
> out.println(" </BODY>");
> out.println("</HTML>");
> out.close();
> c.close();
> } catch(SQLException sx) {
> ServletOutputStream err = res.getOutputStream();
> res.setContentType("text/html");
> err.println("<HTML>\n <HEAD>\n <TITLE>Live Links - SQL
> Exception</TITLE>\n </HEAD>\n <BODY>");
> err.println(" <P>An SQL Exception Occurred while processing the
> request [" + sx.getMessage() + "]");
> err.println(" <UL>");
> err.println(" <LI>conString = " + conString);
> err.println(" <LI>conUser = " + conUser);
> err.println(" <LI>conPwd = " + conPwd);
> err.println(" <LI>table = " + table);
> err.println(" <LI>query = " + query);
> err.println(" </UL>");
> err.println(" </BODY>\n</HTML>");
> err.close();
> }
> } file://doPost
>
> public String getServletInfo () {
> return "Live Link Manager";
> } file://getServletInfo
>
> } file://*Links
>
> ----- Original Message -----
> From: ARCHAIMBAULT SYLVAIN SOPRA <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, September 17, 1999 1:01 AM
> Subject: Re: Stil having Problem with POST FORM
___________________________________________________________________________
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