📄 selectproaction.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.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;/** * MyEclipse Struts * Creation date: 09-10-2007 * * XDoclet definition: * @struts.action path="/selectPro" name="productForm" scope="request" validate="true" */public class SelectProAction extends Action { public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { ProductForm f = (ProductForm) form; /** * 根据条件查询商品信息 * @param actionMapping ActionMapping * @param actionForm ActionForm * @param request HttpServletRequest * @param response HttpServletResponse * @return ActionForward */ ActionForward forward = new ActionForward(); //定义数据对象 Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; //取得查询条件 String productName = f.getProduct_name();//商品名称 String productId = f.getProduct_id();//商品编号 String state = f.getState();//商品状态 String price = f.getPrice();//商品价格 String startDate = f.getStart_date();//有效开始日期 String endDate = f.getEnd_date();//有效结束日期 String showMain = f.getShow_main();//是否在首页显示 String showCommand = f.getShow_command();//是否为推荐商品 HttpSession session=request.getSession(); ArrayList productList = new ArrayList(); try { conn = DBConnection.getConnection(); String sql = "select * from producttable1 where 1=1 "; String link = sql; if(productName != null && !productName.equals("")){ link = link + " and product_name='" + productName + "'"; } if(productId != null && !productId.equals("")){ link = link + " and product_id=" + productId; } if(state != null && !state.equals("")){ link = link + " and state='" + state + "'"; } if(price != null && !price.equals("")){ link = link + " and price=" + price; } if(startDate != null && !startDate.equals("")){ link = link + " and start_date='" + startDate + "'"; } if(endDate != null && !endDate.equals("")){ link = link + " and end_date='" + endDate + "'"; } if(showMain != null && !showMain.equals("")){ link = link + " and show_main='" + showMain + "'"; } if(showCommand != null && !showCommand.equals("")){ link = link + " and show_command='" + showCommand + "'"; } sql = link; pstmt = conn.prepareStatement(sql); rs = pstmt.executeQuery(); while (rs.next()) { f.setProduct_id(String.valueOf(rs.getInt("product_id"))); f.setProduct_name(rs.getString("product_name")); f.setNew_level(rs.getString("new_level")); f.setPrice(String.valueOf(rs.getString("price"))); f.setStart_date(rs.getString("start_date")); f.setEnd_date(rs.getString("end_date")); f.setDescription(rs.getString("description")); f.setAddress_picture(rs.getString("address_picture")); f.setState(rs.getString("state")); f.setStore_number(rs.getString("store_number")); f.setShow_main(rs.getString("show_main")); f.setShow_command(rs.getString("show_command")); f.setAddress(rs.getString("address")); f.setMeno(rs.getString("meno")); f.setCreate_time(rs.getString("create_time")); productList.add(f); } session.setAttribute("productList", productList); forward = mapping.findForward("selectProduct"); } catch (Exception e) { System.out.println(e.getMessage()); forward =mapping.findForward("error"); } 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 + -