| Код | public class TestAction extends Action { int age; String name ; ArrayList list = new ArrayList(); public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String target = new String("success"); DataSource ds; Connection conn=null; Statement statement=null; try{ ds = getDataSource(request, "userDB"); conn = ds.getConnection(); statement = conn.createStatement(); ResultSet rs = statement.executeQuery("SELECT * FROM Table1");
while (rs.next()) { age = rs.getInt(1); name = rs.getString(2);
Data data = new Data(); data.setAge(String.valueOf(age)); data.setName(name); list.add(data); } request.setAttribute("some", list);
}catch(SQLException e) { e.printStackTrace(); }
finally { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } }
return (mapping.findForward(target)); } }
|
Для этого перехода в struts-config.xml
| Код | <action path="/index" type="pack.TestAction" scope="request" > <forward name="success" path="/new.jsp"/> </action>
|
|