html:submit property="dynBtn"
bean:message bundle="resource" key="btn.form.add"
html:submit
nothing special
Wednesday, August 31, 2011
LookupDispatchAction - Struts-Config
name="DynamicCallActionForm"
path="/dynamicCall"
scope="session"
type="com.dynamicCall.DynamicCallAction">
LookupDispatchAction - Action Class
protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("btn.form.add", "addMethod");
map.put("btn.form.remove", "removeMethod");
return map;
}
Map map = new HashMap();
map.put("btn.form.add", "addMethod");
map.put("btn.form.remove", "removeMethod");
return map;
}
get something
public List getDepartments(){
List list = new ArrayList();
PreparedStatement ps = null;
ResultSet rs = null;
String query = "select dep_id,dep_name from department";
try{
ps = (PreparedStatement) con.prepareStatement(query);
rs = ps.executeQuery();
while(rs.next()){
Department d = new Department();
d.setDepId(rs.getInt(1));
d.setDepName(rs.getString(2));
list.add(d);
}
}catch(Exception e){
e.printStackTrace();
}
return list;
}
List
PreparedStatement ps = null;
ResultSet rs = null;
String query = "select dep_id,dep_name from department";
try{
ps = (PreparedStatement) con.prepareStatement(query);
rs = ps.executeQuery();
while(rs.next()){
Department d = new Department();
d.setDepId(rs.getInt(1));
d.setDepName(rs.getString(2));
list.add(d);
}
}catch(Exception e){
e.printStackTrace();
}
return list;
}
input something
public void addStudent(Student s) {
PreparedStatement pst = null;
String query = "insert into student values (?,?,?)";
try{
pst= (PreparedStatement) con.prepareStatement(query);
pst.setInt(1, s.getsId());
pst.setString(2, s.getsName());
pst.setInt(3, s.getDepId());
pst.execute();
}catch(Exception e){
System.out.println(e);
}
}
PreparedStatement pst = null;
String query = "insert into student values (?,?,?)";
try{
pst= (PreparedStatement) con.prepareStatement(query);
pst.setInt(1, s.getsId());
pst.setString(2, s.getsName());
pst.setInt(3, s.getDepId());
pst.execute();
}catch(Exception e){
System.out.println(e);
}
}
Tuesday, August 30, 2011
In Persistence
private Connection con;
public StudentPersistence(Connection con) {
this.con = con;
}
public void conClose() {
try {
this.con.close();
} catch (Exception e) {
System.out.println(e);
}
}
public StudentPersistence(Connection con) {
this.con = con;
}
public void conClose() {
try {
this.con.close();
} catch (Exception e) {
System.out.println(e);
}
}
Subscribe to:
Posts (Atom)