Monday, July 23, 2012

1.1. Basic Struts Example...


UserFormBean.java

package coreservlets;
import java.sql.*;
import org.apache.struts.action.*;


public class UserFormBean extends ActionForm {
  private String email = "Missing address";
  private String password = "Missing password";
  public String getEmail() {
    return(email);
  }


  public String getName()
  {
Connection con=null;
String name="not defined";
try{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql:///omdatabase","root","root");
Statement stat=con.createStatement();
ResultSet rs=stat.executeQuery("Select * from Student");
while(rs.next())
{
name=rs.getString(1);
}
}
catch(Exception ex)
{
name=""+ex;
}
return name;
  }
  public void setEmail(String email) {
    this.email = email;
  }


  public String getPassword() {
    return(password);
  }


  public void setPassword(String password) {
    this.password = password;
  }
}

No comments:

Post a Comment