📄 selectproductaction.java
字号:
//Created by MyEclipse Struts// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.1.1/xslt/JavaClass.xslpackage com.accp.struts.action;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.ArrayList;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.apache.struts.action.Action;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import com.accp.struts.Bean.DBConnection;import com.accp.struts.form.ProductForm;import com.accp.struts.form.UserLogoForm;/** * MyEclipse Struts * Creation date: 09-09-2007 * * XDoclet definition: * @struts.action validate="true" */public class SelectProductAction extends Action { public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { /** * 查询所有商品 * @param actionMapping ActionMapping * @param actionForm ActionForm * @param servletRequest HttpServletRequest * @param servletResponse HttpServletResponse * @return ActionForward */ ProductForm agentProductForm=null; ActionForward forward = new ActionForward(); //定义数据对象 Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; ArrayList productList = new ArrayList(); HttpSession session=request.getSession(); try { conn = DBConnection.getConnection(); String sql = "select * from producttable1"; pstmt = conn.prepareStatement(sql); rs = pstmt.executeQuery(); while (rs.next()) { System.out.println("productId:"+rs.getInt("product_id")); agentProductForm=new ProductForm(); agentProductForm.setProduct_id(String.valueOf(rs.getInt("product_id"))); agentProductForm.setProduct_name(rs.getString("product_name")); agentProductForm.setNew_level(rs.getString("new_level")); agentProductForm.setPrice(String.valueOf(rs.getFloat("price"))); agentProductForm.setStart_date(rs.getString("start_date")); agentProductForm.setEnd_date(rs.getString("end_date")); agentProductForm.setDescription(rs.getString("description")); agentProductForm.setAddress_picture(rs.getString("address_picture")); agentProductForm.setState(rs.getString("state")); agentProductForm.setStore_number(rs.getString("store_number")); agentProductForm.setShow_main(rs.getString("show_main")); agentProductForm.setShow_command(rs.getString("show_command")); agentProductForm.setAddress(rs.getString("address")); agentProductForm.setMeno(rs.getString("meno")); agentProductForm.setCreate_time(rs.getString("create_time")); productList.add(agentProductForm); } System.out.println("size:"+productList.size()); session.setAttribute("productList", productList); forward = mapping.findForward("queryProduct"); } catch (Exception e) { e.printStackTrace(); } finally { try{ if(rs!=null)rs.close(); if(pstmt!=null)pstmt.close(); }catch(SQLException ex){ System.out.println(ex); forward =mapping.findForward("error"); } } System.out.println("forward:" + forward); return forward; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -