Struts入门学习经典实例教程

源代码在线查看: myaction.java~5~

软件大小: 1085 K
上传用户: siclj
关键词: Struts 教程
下载地址: 免注册下载 普通下载 VIP

相关代码

				package strutsdemo.actions;
				
				import org.apache.struts.action.ActionMapping;
				import org.apache.struts.action.ActionForm;
				import javax.servlet.http.HttpServletRequest;
				import javax.servlet.http.HttpServletResponse;
				import org.apache.struts.action.ActionForward;
				import strutsdemo.forms.myActionForm;
				import org.apache.struts.action.Action;
				import java.sql.*;
				
				public class myAction
				    extends Action {
				  public ActionForward execute(ActionMapping actionMapping,
				                               ActionForm actionForm,
				                               HttpServletRequest servletRequest,
				                               HttpServletResponse servletResponse) {
				  java.sql.Connection con=this.getConn();
				  Statement stmt = null;
				  java.util.List list=new java.util.ArrayList();
				  java.util.Map map=null;
				
				  try {
				    stmt = con.createStatement();
				    java.sql.ResultSet rs=stmt.executeQuery("SELECT key,content FROM map");
				    while(rs.next()){
				      map=new java.util.HashMap();
				      map.put(rs.getString("key"),rs.getString("map"));
				      list.add(map);
				
				    }
				  }
				  catch (SQLException ex) {
				    ex.printStackTrace();
				  }
				  servletRequest.setAttribute("data",list);
				  return actionMapping.findForward("output");
				
				
				  }
				
				  private java.sql.Connection getConn(){
				   java.sql.Connection con=null;
				   try {
				     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
				     con=java.sql.DriverManager.getConnection("dbc:odbc:MSdb");
				
				   }
				   catch (Exception ex) {
				     ex.printStackTrace();
				   }
				   return con;
				  }
				}
							

相关资源