Luciano wrote:

> If your bean is in the package email
> and compile into c:\orion\default-site\beans\ 
> you should have in your classpath:

> c:\orion\default-site\beans\
> not
> c:\orion\default-site\beans\email;

Thanks, I got the code to compile with your suggestion.  I have just ran
into any snag.  I am now getting the following Error when I run the code
(the update source codes are included below):
500 Internal Server Error
java.lang.NoClassDefFoundError: email/EmailBean
        at EmailServlet.<init>(EmailServlet.java:9)
        at java.lang.Class.newInstance0(Native Method)
        at java.lang.Class.newInstance(Class.java, Compiled Code)
        at com.evermind.server.http.HttpApplication.l2(JAX, Compiled Code)
        at com.evermind.server.http.HttpApplication.lu(JAX)
        at com.evermind.server.http.HttpApplication.kk(JAX, Compiled Code)
        at c_.k2(JAX, Compiled Code)
        at c.run(JAX, Compiled Code)

File1:  email.jsp
<jsp:useBean id="mailing" scope="session" class="email.EmailBean" />
<jsp:setProperty name="mailing" property="*" />

<html>
<head>
<title>Register Email</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF">
<p>&nbsp;</p>
<p>If you want to be notified please enter your e-mail below</p>
<form method="post" action="/servlet/EmailServlet">
  <table border="1" cellspacing="2" cellpadding="2">
    <tr>
      <td >e-mail:</td>
      <td colspan="2">
        <input type="text" name="email" size="50" maxlength="50">
      </td>
    </tr>
    <tr>
      <td >&nbsp;</td>
      <td >
        <div align="center">
          <input type="submit" name="Subscribe" value="Subscribe">
        </div>
      </td>
      <td >
        <div align="center">
          <input type="submit" name="Unsubscribe" value="Unsubscribe">
        </div>
      </td>
    </tr>
  </table>
</form>
</body>
</html


File2: EmailBean.java
---------------------
package email;

public class EmailBean {

        private String email = null;

        public EmailBean(){
        }

        public void setEmail(String email){
                this.email = email;
        }

        public String getEmail(){
                return email;
        }

}

File3:  EmailServlet.java
-------------------------


import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import email.EmailBean;

public class EmailServlet extends HttpServlet{

    private Connection con = null;
    private PreparedStatement ps = null;
    private String email = null;
    private String userName = "";
    private String password = "";
    private String driverName = "sun.jdbc.odbc.JdbcOdbcDriver";
    private String connectionURL = "jdbc:odbc:emailsource";
    public  EmailBean mail = new EmailBean();;


    public void init(ServletConfig config) throws ServletException{
         super.init(config);
       }

    public void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException{

        request.getSession(true);

      try {
          Driver d = (Driver)Class.forName(driverName).newInstance();
      } catch (Exception e) {
        System.out.println(e);
      }


      try{
        con = DriverManager.getConnection(connectionURL,userName,password);
      }catch(Exception e){
        System.out.println(e);
        }

     email = mail.getEmail();
     System.out.println("debug:  Got here " +  email);

     try{

      ps = con.prepareStatement("INSERT into EmailContacts " +
                        "(Email) " +
                        "values(?)");

      // set the statement values

      ps.setString(1, email);


       // execute the statement
      ps.executeUpdate();

      // rc = true;
      con.commit();
      con.close();
      System.out.println("Debug -- Got Here" + " " + email);


    }
    catch(SQLException e){
      System.out.println(e);
    }
    catch(NullPointerException ex){
     System.out.println(ex);
    }

    try {
            // Set the attribute and Forward to hello.jsp
         request.setAttribute ("servletName", "servletToJsp");
 
getServletConfig().getServletContext().getRequestDispatcher("/examples/jsp/v
ote/thankyou.jsp").forward(request, response);
    } catch (Exception ex) {
          ex.printStackTrace ();
      }
    }

}

Reply via email to