系统说明

javaweb的宠物管理系统,分为前后台,主要功能如下:

商品管理、订单、购物车、管理员、远远管理、公告等
在这里插入图片描述

系统页面截图

登录页面:
会员登录
在这里插入图片描述
管理员登录:
在这里插入图片描述
商品信息管理页面:
在这里插入图片描述
狗狗展示:

在这里插入图片描述
在线留言:
在这里插入图片描述
会员管理页面:
在这里插入图片描述
订单及购物车:
在这里插入图片描述

主要代码实现

controller层:
DrowDownList:

package com.itbaizhan.daowen.webcontrol;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;
import java.util.Iterator;

import javassist.bytecode.Opcode;

import javax.activation.DataSource;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import com.itbaizhan.daowen.util.NameUtil;


public class DropdownList  extends BodyTagSupport{

	
	 private String id;
	 
	 
	 
	 private String name;
	/***********
	 * 绑定数据源
	 */
	private   Object  datasource;
	
	
	/***
	 * 绑定域名
	 */
	private String textfieldname;
	
	
	
	/**
	 * 绑定值名
	 * */
	private String valuefieldname;
	
	/*****
	 * 样式类名
	 */
	private  String cssclass;
	
	/***
	 * 样式
	 */
	private  String style;
	
	
	private String  value;
	
	
	
	@Override
	public int doStartTag(){
		
      StringBuffer sb=new StringBuffer();
	  String controlname="";
	  String classname="";
	  if(name!=null)
		   controlname="name=\""+name+"\"";
	  if(cssclass!=null)
		   classname=" class=\""+cssclass+"\"";
	  sb.append(MessageFormat.format("<select {0} id=\"{1}\" {2} >",controlname,id,classname));
	 
	  JspWriter out=pageContext.getOut();
	  
	  
	  try {
		out.write(sb.toString());
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	  
	   return  EVAL_BODY_INCLUDE;
	}
	
	@Override
	
	public  int doAfterBody()
	{
		
		
		if(datasource==null)
			
			return SKIP_BODY;
		
		JspWriter writer=pageContext.getOut();
		 
		StringBuffer sb=new StringBuffer();
		
		sb.append(getDsRender());
		
		try {
			writer.write(sb.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return SKIP_BODY;
	}
	

	@Override
	public int doEndTag() {
	    
		
	      StringBuffer sb=new StringBuffer();
			
		  sb.append("</select >");
		 
		  JspWriter out=pageContext.getOut();
		  
		  
		  try {
			out.write(sb.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	    return EVAL_PAGE;
	}
	
	
	/*****
	 * 获取控件呈现
	 * @return
	 */
	private String getDsRender(){
		
		StringBuffer sb=new StringBuffer();
		
		
			
		//获取数据源
		Iterable e=(Iterable)datasource;
		
		if(e==null)
			return "";
		
		//如果数据源不为空
		if(e!=null){
			Iterator it=e.iterator();
			//遍历记录集
			while (it.hasNext()){
				
				//获取数据集元素
				Object object=it.next();
				String optiontext="";
				String optionvalue="";
				try {
					optiontext=object.getClass().getMethod("get"+NameUtil.toFirstUpper(getTextfieldname()), null).invoke(object, null).toString();
					optionvalue=object.getClass().getMethod("get"+NameUtil.toFirstUpper(getValuefieldname()), null).invoke(object, null).toString();
				} catch (IllegalArgumentException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (SecurityException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (IllegalAccessException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (InvocationTargetException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (NoSuchMethodException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				String optionvaluefield="";
				if(optionvalue!=null){
					optionvaluefield=" value=\""+optionvalue+"\"";
				}
				String optionselectfield="";
				
				if(value!=null&&value.equals(optionvalue))
					optionselectfield=" selected=\"selected\"";
				
				sb.append(MessageFormat.format("<option  {1}  {2}>{0}</option>",optiontext,optionvaluefield,optionselectfield));
				
				
			}
		}
	    
		
		return sb.toString();
	}
	
	    
	public void setDatasource(Object datasource) {
		

		
		this.datasource=datasource;
//	    try {
//		  
//			this.datasource=ExpressionEvaluatorManager.evaluate("datasource", dsname.toString(), Object.class, this, pageContext);
//			
//			 
//		} catch (JspException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		
	}



	public String getTextfieldname() {
		return textfieldname;
	}



	public void setTextfieldname(String textfieldname) {
		this.textfieldname = textfieldname;
	}



	public String getValuefieldname() {
		return valuefieldname;
	}



	public void setValuefieldname(String valuefieldname) {
		this.valuefieldname = valuefieldname;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Object getDatasource() {
		return datasource;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCssclass() {
		return cssclass;
	}

	public void setCssclass(String cssclass) {
		this.cssclass = cssclass;
	}

	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

    
    
	
	
}

ListItem:

package com.itbaizhan.daowen.webcontrol;

import java.io.IOException;
import java.text.MessageFormat;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;

/*******************************************************************************
 * 
 * 列表选项卡
 * 
 */
public class ListItem extends BodyTagSupport {

	private String value;

	/***************************************************************************
	 * 当前父控件是否绑定了数据源
	 * 
	 * @return 绑定返回真 ,否则为假
	 * 
	 */
	public ListItem(){
		
	}
	private Boolean hasBindingDatasource() {

	   Object parent=getParent();
	   
	   if(parent==null)
		   return false;
	   
	   String pclassname = getParent().getClass().getName();
	   
	   if(pclassname.equals("com.daowen.webcontrol.DropdownList"))
	   {
		   if(((DropdownList)getParent()).getDatasource()==null)
			     return false;
			else 
				return true;
		   
	   }
	   if(pclassname.equals("com.daowen.webcontrol.RadioButtonList"))
	   {
		   if(((RadioButtonList)getParent()).getDatasource()==null)
			     return false;
			else 
				return true;
		   
	   }
		 
		   
		   
		return false;
	}

	@Override
	public int doStartTag() {

		if (getParent() == null) {
			try {
				pageContext.getOut().write("");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return SKIP_BODY;
		}
		return EVAL_BODY_BUFFERED;
	}

	@Override
	public void setBodyContent(BodyContent bc) {
		super.setBodyContent(bc);

	}

	@Override
	public int doAfterBody() throws JspException {

		if (getParent() == null)
			return SKIP_BODY;
		
		String bodycontent="";
		
		JspWriter out=getBodyContent().getEnclosingWriter();
		// 父控件类名
		String pclassname = getParent().getClass().getName();

		System.out.println("parent control name=" + pclassname);

		// 如果父控件已经绑定数据源,那么当前控件设置数据项被覆盖
		if (hasBindingDatasource())

			return SKIP_BODY;
		//根据父控件的类型进行呈现数据选项
		if(pclassname.equals("com.daowen.webcontrol.DropdownList"))
			
			bodycontent=buildDropdownlistItems();
		
		if(pclassname.equals("com.daowen.webcontrol.RadioButtonList"))
		{
			String temtext=getBodyContent().getString();
			String temvalue=value==null?temtext:value;
		    bodycontent=buildRadioButtonItem(temtext, temvalue);
		}
		try {
			
			out.write(bodycontent);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return SKIP_BODY;

		

	}
	
	
	/************
	 * 显示DropdownList 控件选项
	 */
	private String buildDropdownlistItems(){
		
		BodyContent bc = getBodyContent();

	
		StringBuffer sb = new StringBuffer();
		
		DropdownList parent=(DropdownList)getParent();
		
		String parentvalue = parent.getValue();
		
		
        String optionvalue="";
        String temvalue=value;
        
        
		if (temvalue != null)
           
			optionvalue = "value=\"" + temvalue + "\"";
		else
		{
			temvalue=bc.getString();
			optionvalue = "value=\"" + temvalue + "\"";
		}
		
		String select="";
		//如果当前选项卡为控件值则设置选择
		if(temvalue.equals(parentvalue))
			
			select=" selected=\"selected\" ";
		
		sb.append(MessageFormat.format("<option {1} {2} >{0}</option>", bc
				.getString(), optionvalue,select));

		return sb.toString();

		
	}
private String buildRadioButtonItem(String text,String value){
		
	StringBuffer sb=new StringBuffer();
	
	RadioButtonList rbl=(RadioButtonList)getParent();
	if(rbl==null)
		return "";
	
	String name=rbl.getName();
	
	//值属性
	String valueattr="";
	if(valueattr!=null){
		valueattr=" value=\""+value+"\"";
	}
	//check属性
	String checkattr="";
	
	if(this.value!=null&&this.value.equals(value))
		checkattr=" checked=\"checked\"";
    String nameattr="";
    
    if(name!=null)
		nameattr=" name=\""+name+"\"";
	
	sb.append(MessageFormat.format("<input {0} type=\"radio\"  {1}  {2} />{3}",nameattr,valueattr,checkattr,text));
	
	
	
	return sb.toString();
		
	}

	@Override
	public int doEndTag() {
		return EVAL_PAGE;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

}

RadioButtonList:

package com.itbaizhan.daowen.webcontrol;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;
import java.util.Iterator;

import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import com.itbaizhan.daowen.util.NameUtil;

public class RadioButtonList extends BodyTagSupport {

	private String id;

	private String name;
	/***************************************************************************
	 * 绑定数据源
	 */
	private Object datasource;

	/***************************************************************************
	 * 绑定域名
	 */
	private String textfieldname;

	/**
	 * 绑定值名
	 */
	private String valuefieldname;

	/***************************************************************************
	 * 样式类名
	 */
	private String cssclass;

	/***************************************************************************
	 * 样式
	 */
	private String style;

	private String value;

	public String getCssclass() {
		return cssclass;
	}

	public void setCssclass(String cssclass) {
		this.cssclass = cssclass;
	}

	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	public int doStartTag() {

		StringBuffer sb = new StringBuffer();
		String controlname = "";

		if (name != null)
			controlname = "name=\"" + name + "\"";
		sb.append(MessageFormat.format("<div {0} id=\"{1}\">",
						controlname, id));

		JspWriter out = pageContext.getOut();

		try {
			out.write(sb.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return EVAL_BODY_INCLUDE;
	}

	public int doAfterBody() {
		
		if (datasource == null)

			return SKIP_BODY;

		JspWriter writer = pageContext.getOut();

		StringBuffer sb = new StringBuffer();

		sb.append(getDsRender());

		try {
			writer.write(sb.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return SKIP_BODY;
	}

	private String getDsRender() {
		
		StringBuffer sb=new StringBuffer();
		
		
		
		//获取数据源
		Iterable e=(Iterable)datasource;
		
		if(e==null)
			return "";
		
		//如果数据源不为空
		if(e!=null){
			Iterator it=e.iterator();
			//遍历记录集
			while (it.hasNext()){
				
				//获取数据集元素
				Object object=it.next();
				String itemtext="请制定绑定text域名";
				String itemvalue="请制定绑定value域名";
				try {
				    if(valuefieldname!=null&&textfieldname!=null){
					   itemtext=object.getClass().getMethod("get"+NameUtil.toFirstUpper(getTextfieldname()), null).invoke(object, null).toString();
					   itemvalue=object.getClass().getMethod("get"+NameUtil.toFirstUpper(getValuefieldname()), null).invoke(object, null).toString();
				    }
				} catch (Exception e1) {
					
					e1.printStackTrace();
				} 
			
				//构建radiobutton
				sb.append(buildRadiobutton(itemtext, itemvalue));
				
			}//end while
		}
	    
		
		return sb.toString();
		
		
	}
	
	private String buildRadiobutton(String text,String value){
		
		StringBuffer sb=new StringBuffer();
		
		//值属性
		String valueattr="";
		if(valueattr!=null){
			valueattr=" value=\""+value+"\"";
		}
		//check属性
		String checkattr="";
		
		if(this.value!=null&&this.value.equals(value))
			checkattr=" checked=\"checked\"";
	    String nameattr="";
	    
	    if(name!=null)
			nameattr=" name=\""+name+"\"";
		
		sb.append(MessageFormat.format("<input {0} type=\"radio\"  {1}  {2} />{3}",nameattr,valueattr,checkattr,text));
		
		
		
		return sb.toString();
		
		
	}

	public int doEndTag() {

		StringBuffer sb = new StringBuffer();

		sb.append("</div>");

		JspWriter out = pageContext.getOut();

		try {
			out.write(sb.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return EVAL_PAGE;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Object getDatasource() {
		return datasource;
	}

	public void setDatasource(Object datasource) {
		this.datasource = datasource;
	}

	public String getTextfieldname() {
		return textfieldname;
	}

	public void setTextfieldname(String textfieldname) {
		this.textfieldname = textfieldname;
	}

	public String getValuefieldname() {
		return valuefieldname;
	}

	public void setValuefieldname(String valuefieldname) {
		this.valuefieldname = valuefieldname;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

}

Action层:
订单:

package com.itbaizhan.daowen.action;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.itbaizhan.daowen.bll.SystemParam;
import com.itbaizhan.daowen.dal.DALBase;
import com.itbaizhan.daowen.entity.Attachement;
import com.itbaizhan.daowen.entity.Dingdan;
import com.itbaizhan.daowen.entity.Dingdanitems;
import com.itbaizhan.daowen.entity.Huiyuan;
import com.itbaizhan.daowen.entity.Shangpin;
import com.itbaizhan.daowen.util.PagerMetal;


public class DingdanAction extends PageActionBase {
	public void onLoad() {
		String actiontype = request.getParameter("actiontype");
		System.out.println("actiontype=" + actiontype);
		if (actiontype == null)
			return ;
		
		if(actiontype.equals("modifyAmount")){
			modifyAmount();
		}
		if (actiontype.equals("shopcart")) {
			shopcart();
		}
		if (actiontype.equals("clearshopcart")) {
			clearshopcart();
		}
		if (actiontype.equals("removeShangpin")) {
			removeShangpin();
		}
		if(actiontype.equals("payfor"))
			fukuan();
		if(actiontype.equals("fahuo"))
			fahuo();
		
	}

	private void fahuo() {
		
        String ddid=request.getParameter("ddid");
		
        String fahuoren=request.getParameter("fahuoren");
        
        
		
		if(ddid!=null)
		{
			Dingdan  dingdan=(Dingdan)DALBase.load("dingdan", "where id="+ddid);
			
			dingdan.setStatus("已发货");
			dingdan.setFahuoren(fahuoren);
			dingdan.setFahuotime(new Date());
			DALBase.update(dingdan);
			
			
		}
		String forwardurl = request.getParameter("forwardurl");
	 		if (forwardurl != null)
	 			try {
	 				response.sendRedirect(SystemParam.getSiteRoot() + forwardurl);
	 			} catch (IOException e) {
	 				// TODO Auto-generated catch block
	 				e.printStackTrace();
	 	}
		
	}

	private void fukuan() {
		
		
		String ddid=request.getParameter("ddid");
		
        String accountname=request.getParameter("accountname");
       
        String  errorurl=request.getParameter("errorurl");
		
		if(ddid!=null)
		{
			Dingdan  dingdan=(Dingdan)DALBase.load("dingdan", "where id="+ddid);
			
			if(accountname!=null)
			{
		    	Huiyuan  hy=(Huiyuan)DALBase.load("huiyuan", "where accountname='"+accountname+"'");
		    	
		    	if(hy.getYue()<dingdan.getTotalprice()){
		    		
		    		request.setAttribute("errormsg", "<label class='error'>账户余额不足于支付订单,请充值</label>");
		    		try {
						request.getRequestDispatcher("/e/huiyuan/fukuan.jsp?id="+ddid).forward(request, response);
						
						return;
					} catch (ServletException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
		    		
		    	}else {
					
		    		hy.setYue((float)(hy.getYue()-dingdan.getTotalprice()));
		    		hy.setJifen(hy.getJifen()+(int)dingdan.getTotalprice());
		    		DALBase.update(hy);

					dingdan.setStatus("已付款");
					DALBase.update(dingdan);
		    		request.getSession().setAttribute("huiyuan", hy);
				}
		    	
			}
			
			
		}
		String forwardurl = request.getParameter("forwardurl");
	 		if (forwardurl != null)
	 			try {
	 				response.sendRedirect(SystemParam.getSiteRoot() + forwardurl);
	 			} catch (IOException e) {
	 				// TODO Auto-generated catch block
	 				e.printStackTrace();
	 	}
		
		
		
		
		
	}

	/*
	 * 修改购物车数量
	 * */
	private void modifyAmount(){
		
		 String spid=request.getParameter("spid");
		 String shuliang=request.getParameter("shuliang");
		 List<Dingdanitems> temlist=(List<Dingdanitems>)request.getSession().getAttribute("cart");
	   	   if(temlist!=null)
	   	   {
	         for(Iterator<Dingdanitems> it= temlist.iterator();it.hasNext();)
	         {
	       	  
		       	  Dingdanitems ddi=it.next();
		       	 
		       	  if(ddi.getSpid()==new Integer(spid))
		       	  {
		       		     
		       	       ddi.setShuliang(new Integer(shuliang));
		       	       
		       	       
		       	  }
		       	  
	       	  
	         }
	   	   }
	   	   calcuateTotalfee();
	       String forwardurl = request.getParameter("forwardurl");
	 		if (forwardurl != null)
	 			try {
	 				response.sendRedirect(SystemParam.getSiteRoot() + forwardurl);
	 			} catch (IOException e) {
	 				// TODO Auto-generated catch block
	 				e.printStackTrace();
	 		}
			
	}
	
	private void removeShangpin() {
		
		
      String spid=request.getParameter("spid");
   	 
   	   List<Dingdanitems> temlist=(List<Dingdanitems>)request.getSession().getAttribute("cart");
   	   if(temlist!=null)
   	   {
         for(Iterator<Dingdanitems> it= temlist.iterator();it.hasNext();)
         {
       	  
	       	  Dingdanitems ddi=it.next();
	       	 
	       	  if(ddi.getSpid()==new Integer(spid))
	       	  {
	       		     
	       	       it.remove();
	       	       float totalfee=Float.parseFloat(request.getSession().getAttribute("totalfee").toString());
	       	       
	       	       totalfee-=ddi.getShuliang()* Float.parseFloat(ddi.getJiage());
	       	       
	       	       request.getSession().setAttribute("totalfee", totalfee);

	       			 
	       	  }
	       	  
       	  
         }
   	   }
        String forwardurl = request.getParameter("forwardurl");
 		if (forwardurl != null)
 			try {
 				response.sendRedirect(SystemParam.getSiteRoot() + forwardurl);
 			} catch (IOException e) {
 				// TODO Auto-generated catch block
 				e.printStackTrace();
 		}
		
	}

	private void clearshopcart() {

		request.getSession().removeAttribute("cart");
		request.getSession().removeAttribute("totalfee");
		String forwardurl = request.getParameter("forwardurl");
		if (forwardurl != null)
			try {
				response.sendRedirect(SystemParam.getSiteRoot() + forwardurl);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

	}
	
	private void calcuateTotalfee()
	{
		List<Dingdanitems> cart = (List<Dingdanitems>) request.getSession()
				.getAttribute("cart");
		int totalfee=0;
		for (Dingdanitems dditem : cart) {
			totalfee += dditem.getShuliang()
					* new Double(dditem.getJiage());
		
		}
		request.getSession().setAttribute("totalfee", totalfee);

	}

	private void shopcart() {

		String forwardurl = request.getParameter("forwardurl");
		// 商品ID
		String spid = request.getParameter("spid");
		// 商品名
		String spname2 = request.getParameter("spname");
		//
		String command = request.getParameter("command");
		// request.setCharacterEncoding("UTF-8");
		float totalfee = 0;
		
		List<Dingdanitems> cart = (List<Dingdanitems>) request.getSession()
				.getAttribute("cart");

		if (spid != null) {

			if (cart == null) {

				cart = new ArrayList<Dingdanitems>();
				request.getSession().setAttribute("cart", cart);

			}
			Shangpin addshangpin = (Shangpin) DALBase.load("shangpin",
					"where id=" + spid);

			Boolean hasin = false;

			for (Dingdanitems dditem : cart) {
				System.out.println("addshangpin.getId()" + addshangpin.getId());
				System.out.println("dditem.getId()" + dditem.getId());
				if (addshangpin.getId() == dditem.getSpid()) {

					hasin = true;
					if (command!=null&&command.equals("modifyCount")) {
						String shuliang = request.getParameter("shuliang");
						dditem.setShuliang(new Integer(shuliang));
					} else
						dditem.setShuliang(dditem.getShuliang() + 1);

				}
				totalfee += dditem.getShuliang()
						* new Double(dditem.getJiage());
			}
			if (!hasin) {
				Dingdanitems temitem = new Dingdanitems();
				temitem.setSpname(addshangpin.getName());
				temitem.setSpimage(addshangpin.getTupian());
				temitem.setSpno(addshangpin.getSpno());
				temitem.setSpid(addshangpin.getId());
				temitem.setShuliang(1);
				temitem.setJiage(String.valueOf(addshangpin.getJiage()));
				totalfee += addshangpin.getJiage();
				cart.add(temitem);

			}

		}
		
		request.getSession().setAttribute("totalfee", totalfee);

		if (forwardurl != null)
			try {
				response.sendRedirect(SystemParam.getSiteRoot() + forwardurl);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

	}

	/********************************************************
	 ****************** 信息注销监听支持*****************************
	 *********************************************************/
	public void delete() {
		String id = request.getParameter("id");
		DALBase.delete("dingdan", " where id=" + id);
		binding();
	}

	/*************************************************************
	 **************** 保存动作监听支持******************************
	 **************************************************************/
	public void save() {
		
	
		String shouhuodizhi = request.getParameter("shouhuodizhi");
		String shrtel = request.getParameter("shrtel");
		String shraddress = request.getParameter("shraddress");
		String shrname = request.getParameter("shrname");
		
		String des = request.getParameter("des");
		String xdren=request.getParameter("xdren");
		String status=request.getParameter("status");
		
		List<Dingdanitems> listitems=(List<Dingdanitems>)request.getSession().getAttribute("cart");
		
		if(listitems==null){
			try {
				response.sendRedirect(SystemParam.getSiteRoot()+"/e/shangpinlist.jsp");
			} catch (IOException e) {
				
				e.printStackTrace();
			}
			return;
		}
		
		
		SimpleDateFormat sdfdingdan = new SimpleDateFormat("yyyy-MM-dd");
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyymmddHHMMss");
		
		String timestamp = sdf.format(new Date());
		
		Dingdan dingdan = new Dingdan();
		dingdan.setDdno("dd"+timestamp);
		
		Double totalprice=0.0;
        for(Dingdanitems dd : listitems){
			
			dd.setDdno(dingdan.getDdno());
			dd.setDes(xdren+"购买"+dd.getSpname());
			totalprice+=Double.valueOf(dd.getJiage())*dd.getShuliang();
			
			DALBase.save(dd);
			
		}
		
		
		
		dingdan.setTitle("");
		
		dingdan.setXiadantime(new Date());
		
		dingdan.setXiadanren(xdren);
		dingdan.setTotalprice(totalprice);
		
		//dingdan.setStatus("待付款");
		dingdan.setStatus(status);
		
		dingdan.setFahuotime(new Date());
		//收货地址
		dingdan.setShouhuodizhi(shouhuodizhi);
		dingdan.setShrtel(shrtel);
		dingdan.setShraddress(shraddress);
		dingdan.setShrname(shrname);
		
		dingdan.setDes(des);
		DALBase.save(dingdan);
		
		clearshopcart();
	}

	/******************************************************
	 *********************** 内部附件支持*********************
	 *******************************************************/
	public void attachements(HttpServletRequest request,
			HttpServletResponse response, String belongid) {
		DALBase.delete("attachement", MessageFormat.format(
				" where belongid=''{0}'' and belongtable=''dingdan'' ",
				belongid));
		String[] photos = request.getParameterValues("fileuploaded");
		if (photos == null)
			return;
		for (int i = 0; i < photos.length; i++) {
			Attachement a = new Attachement();
			a.setType("images");
			a.setPubtime(new Date());
			a.setBelongfileldname("id");
			a.setFilename(photos[i]);
			a.setBelongid(belongid);
			a.setBelongtable("dingdan");
			a.setUrl(SystemParam.getSiteRoot() + "/upload/temp/"
					+ a.getFilename());
			a.setTitle(a.getFilename());
			DALBase.save(a);
		}
	}



	/******************************************************
	 *********************** 更新内部支持*********************
	 *******************************************************/
	public void update() {
		String forwardurl = request.getParameter("forwardurl");
		String id = request.getParameter("id");
		if (id == null)
			return;
		Dingdan dingdan = (Dingdan) DALBase
				.load(Dingdan.class, new Integer(id));
		if (dingdan == null)
			return;
		String title = request.getParameter("title");
		String ddno = request.getParameter("ddno");
		String xiadantime = request.getParameter("xiadantime");
		String xiadanren = request.getParameter("xiadanren");
		String totalprice = request.getParameter("totalprice");
		String status = request.getParameter("status");
		String fahuoren = request.getParameter("fahuoren");
		String fahuotime = request.getParameter("fahuotime");
		String shouhuodizhi = request.getParameter("shouhuodizhi");
		String shrtel = request.getParameter("shrtel");
		String shraddress = request.getParameter("shraddress");
		String shrname = request.getParameter("shrname");
		String des = request.getParameter("des");
		SimpleDateFormat sdfdingdan = new SimpleDateFormat("yyyy-MM-dd");
		dingdan.setTitle(title);
		dingdan.setDdno(ddno);
		try {
			dingdan.setXiadantime(sdfdingdan.parse(xiadantime));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		dingdan.setXiadanren(xiadanren);
		dingdan.setTotalprice(totalprice == null ? (double) 0 : new Double(
				totalprice));
		dingdan.setStatus(status);
		dingdan.setFahuoren(fahuoren);
		try {
			dingdan.setFahuotime(sdfdingdan.parse(fahuotime));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		dingdan.setShouhuodizhi(shouhuodizhi);
		dingdan.setShrtel(shrtel);
		dingdan.setShraddress(shraddress);
		dingdan.setShrname(shrname);
		dingdan.setDes(des);
		DALBase.update(dingdan);
		
		binding();
	}

	/******************************************************
	 *********************** 加载内部支持*********************
	 *******************************************************/
	public void load() {
		//
		String id = request.getParameter("id");
		String actiontype = "save";
		dispatchParams(request, response);
		if (id != null) {
			Dingdan dingdan = (Dingdan) DALBase.load("dingdan", "where id="
					+ id);
			if (dingdan != null) {
				request.setAttribute("dingdan", dingdan);
			}
			actiontype = "update";
			request.setAttribute("id", id);
		}
		request.setAttribute("actiontype", actiontype);
		String forwardurl = request.getParameter("forwardurl");
		System.out.println("forwardurl=" + forwardurl);
		if (forwardurl == null) {
			forwardurl = "/admin/dingdanadd.jsp";
		}
		try {
			request.getRequestDispatcher(forwardurl).forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/******************************************************
	 *********************** 数据绑定内部支持*********************
	 *******************************************************/
	public void binding() {
		String filter = "where 1=1 ";
		String xdren=request.getParameter("xiadanren");
		String isurl=request.getParameter("isurl");
		if(xdren!=null)
		{
			
			if(isurl!=null&&isurl.equals("1"))
				try {
					xdren=new String(xdren.getBytes("ISO-8859-1"),"UTF-8");
				} catch (UnsupportedEncodingException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			filter+=" and xiadanren='"+xdren+"'";
		}
		
		
		int pageindex = 1;
		int pagesize = 10;
		// 获取当前分页
		String currentpageindex = request.getParameter("currentpageindex");
		// 当前页面尺寸
		String currentpagesize = request.getParameter("pagesize");
		// 设置当前页
		if (currentpageindex != null)
			pageindex = new Integer(currentpageindex);
		// 设置当前页尺寸
		if (currentpagesize != null)
			pagesize = new Integer(currentpagesize);
		List<Dingdan> listdingdan = DALBase.getPageEnity("dingdan", filter,
				pageindex, pagesize);
		int recordscount = DALBase.getRecordCount("dingdan",
				filter == null ? "" : filter);
		request.setAttribute("listdingdan", listdingdan);
		PagerMetal pm = new PagerMetal(recordscount);
		// 设置尺寸
		pm.setPagesize(pagesize);
		// 设置当前显示页
		pm.setCurpageindex(pageindex);
		// 设置分页信息
		request.setAttribute("pagermetal", pm);
		// 分发请求参数
		dispatchParams(request, response);
		String forwardurl = request.getParameter("forwardurl");
		System.out.println("forwardurl=" + forwardurl);
		if (forwardurl == null) {
			forwardurl = "/admin/dingdanmanager.jsp";
		}
		try {
			request.getRequestDispatcher(forwardurl).forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

会员:

package com.itbaizhan.daowen.action;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.SQLQuery;
import org.hibernate.Query;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.text.MessageFormat;

import com.itbaizhan.daowen.bll.*;
import com.itbaizhan.daowen.dal.*;
import com.itbaizhan.daowen.entity.*;
import com.itbaizhan.daowen.util.DaowenUIHelper;
import com.itbaizhan.daowen.util.ExtHelper;
import com.itbaizhan.daowen.util.HibernateSessionFactory;
import com.itbaizhan.daowen.util.PagerMetal;


public class HuiyuanAction extends PageActionBase {
	public void onLoad() {
		String actiontype = request.getParameter("actiontype");
		System.out.println("actiontype=" + actiontype);
		if (actiontype == null)
			return ;
	
		if (actiontype.equals("login")) {
			login();
		}
		if (actiontype.equals("exit")) 
			exit();
		if (actiontype.equals("modifyPw")) {
			modifyPw();
		}
		if (actiontype.equals("chongzhi")){
			chongzhi();
		 
		}
		
	}

	private void chongzhi() {
		String jine = request.getParameter("jine");
		String forwardurl = request.getParameter("forwardurl");

		String id = request.getParameter("id");
		if (id == null || id == "")
			return;
		Huiyuan huiyuan = (Huiyuan) DALBase
				.load(Huiyuan.class, new Integer(id));
		if (huiyuan != null) {
			huiyuan.setYue(huiyuan.getYue() + Float.parseFloat(jine));
			DALBase.update(huiyuan);
			request.getSession().setAttribute("huiyuan", huiyuan);
			try {
				if (forwardurl != null)
					response.sendRedirect(SystemParam.getSiteRoot()
							+ forwardurl);
			} catch (IOException e) {

				e.printStackTrace();
			}
		}

	}

	private void modifyPw() {

		String password1=request.getParameter("password1");
		String  forwardurl=request.getParameter("forwardurl");
		String repassword1=request.getParameter("repassword1");
		String repassword2=request.getParameter("repassword2");
		String id = request.getParameter("id");
		if (id == null||id=="")
			return;
		Huiyuan huiyuan = (Huiyuan) DALBase.load(Huiyuan.class, new Integer(id));
		if(huiyuan!=null)
		{
			huiyuan.setPassword(repassword1);
			DALBase.update(huiyuan);
			request.getSession().setAttribute("huiyuan", huiyuan);
			try {
				response.sendRedirect(SystemParam.getSiteRoot()+forwardurl);
			} catch (IOException e) {
				
				e.printStackTrace();
			}
		}
		

	}

	private void exit() {

		if (request.getSession().getAttribute("huiyuan") != null) {

			System.out.println("系统退出");
			request.getSession().removeAttribute("huiyuan");

		}

	}

	/********************************************************
	 ****************** 信息注销监听支持*****************************
	 *********************************************************/
	public void delete() {
		String id = request.getParameter("id");
		DALBase.delete("huiyuan", " where id=" + id);
		binding();
	}

	private void login() {

		String usertype = request.getParameter("usertype");

		if (usertype != null && usertype.equals("0")) {
			huiyuanLogin(request, response);
		}

	}

	/***
     * **/
	private void huiyuanLogin(HttpServletRequest request,
			HttpServletResponse response) {

		String accountname = request.getParameter("accountname");
		String password = request.getParameter("password");

		String filter = MessageFormat.format(
				"where accountname=''{0}'' and password=''{1}''", accountname,
				password);

		Huiyuan huiyuan = (Huiyuan) DALBase.load("huiyuan", filter);
		String errorurl=request.getParameter("errorurl");
		String forwardurl=request.getParameter("forwardurl");

		if (huiyuan != null && huiyuan.getPassword().equals(password)) {

			try {

				huiyuan.setLogtimes(huiyuan.getLogtimes() + 1);
				DALBase.update(huiyuan);
				request.getSession().setAttribute("huiyuan", huiyuan);
				if (forwardurl != "")
					response.sendRedirect(SystemParam.getSiteRoot()
							+ forwardurl);

				else {

					response.sendRedirect(SystemParam.getSiteRoot() + "/e/huiyuan/accounintfo.jsp");
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} else {

			dispatchParams(request, response);
			request.setAttribute("errormsg", "<label class='error'>系统账户和密码不匹配<label>");
			try {

				request.getRequestDispatcher(errorurl).forward(request, response);

			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}

	}

	/*************************************************************
	 **************** 保存动作监听支持******************************
	 **************************************************************/
	public void save() {
		String accountname = request.getParameter("accountname");
		String password = request.getParameter("password");
		String xtype = request.getParameter("xtype");

		String email = request.getParameter("email");

		if (DALBase.isExist("huiyuan", "where accountname='" + accountname
				+ "'")) {
			try {
				request.setAttribute("errormsg",
						"<label class='error'>用户名已经存在</label>");
				dispatchParams(request, response);
				request.getRequestDispatcher("/e/register.jsp").forward(
						request, response);
			} catch (ServletException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return;
		}

		Huiyuan huiyuan = new Huiyuan();
		huiyuan.setAccountname(accountname == null ? "" : accountname);
		huiyuan.setPassword(password == null ? "" : password);
		huiyuan.setXtype("");
		huiyuan.setNickname(accountname);

		huiyuan.setRegdate(new Date());

		huiyuan.setLogtimes(0);
		huiyuan.setTouxiang(SystemParam.getSiteRoot()
				+ "/upload/default_tou.gif");
		huiyuan.setEmail(email == null ? "" : email);
		huiyuan.setMobile("");
		huiyuan.setSex("男");
		huiyuan.setAddress("");
		huiyuan.setJibie("初级");
		huiyuan.setName("");
		huiyuan.setZhiye("");
		huiyuan.setAihao("");
		huiyuan.setJifen(10);
		huiyuan.setStatus(1);
		huiyuan.setYue(0);
		huiyuan.setXtype("普通会员");
		DALBase.save(huiyuan);
		try {
			response.sendRedirect("../e/regresult.jsp");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	/******************************************************
	 *********************** 内部附件支持*********************
	 *******************************************************/
	public void attachements(HttpServletRequest request,
			HttpServletResponse response, String belongid) {
		DALBase.delete("attachement", MessageFormat.format(
				" where belongid=''{0}'' and belongtable=''huiyuan'' ",
				belongid));
		String[] photos = request.getParameterValues("fileuploaded");
		if (photos == null)
			return;
		for (int i = 0; i < photos.length; i++) {
			Attachement a = new Attachement();
			a.setType("images");
			a.setPubtime(new Date());
			a.setBelongfileldname("id");
			a.setFilename(photos[i]);
			a.setBelongid(belongid);
			a.setBelongtable("huiyuan");
			a.setUrl(SystemParam.getSiteRoot() + "/upload/temp/"
					+ a.getFilename());
			a.setTitle(a.getFilename());
			DALBase.save(a);
		}
	}

	

	/******************************************************
	 *********************** 更新内部支持*********************
	 *******************************************************/
	public void update() {
		String id = request.getParameter("id");
		if (id == null)
			return;
		Huiyuan huiyuan = (Huiyuan) DALBase
				.load(Huiyuan.class, new Integer(id));
		if (huiyuan == null)
			return;
		String accountname = request.getParameter("accountname");
		
		String nickname = request.getParameter("nickname");
		String forwardurl = request.getParameter("forwardurl");
	
		String touxiang = request.getParameter("touxiang");
		String email = request.getParameter("email");
		String mobile = request.getParameter("mobile");
		String sex = request.getParameter("sex");
		String address = request.getParameter("address");
		String jibie = request.getParameter("jibie");
		String name = request.getParameter("name");
		String zhiye = request.getParameter("zhiye");
		String aihao = request.getParameter("aihao");
		String status = request.getParameter("status");
		SimpleDateFormat sdfhuiyuan = new SimpleDateFormat("yyyy-MM-dd");
		huiyuan.setAccountname(accountname);

		huiyuan.setNickname(nickname);

		huiyuan.setTouxiang(touxiang);
		huiyuan.setEmail(email);
		huiyuan.setMobile(mobile);
		huiyuan.setSex(sex);
		huiyuan.setAddress(address);
		huiyuan.setJibie(jibie);
		huiyuan.setName(name);
		huiyuan.setZhiye(zhiye);
		huiyuan.setAihao(aihao);

		DALBase.update(huiyuan);
		request.getSession().setAttribute("huiyuan", huiyuan);
		try {
		   if(forwardurl!=null)
			  response.sendRedirect(SystemParam.getSiteRoot()+forwardurl);
		   else
			  response.sendRedirect(SystemParam.getSiteRoot()+"/e/huiyuan/modifyinfores.jsp");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	/******************************************************
	 *********************** 加载内部支持*********************
	 *******************************************************/
	public void load() {
		//
		String id = request.getParameter("id");
		String actiontype = "save";
		if (id != null) {
			Huiyuan huiyuan = (Huiyuan) DALBase.load("huiyuan", "where id="
					+ id);
			if (huiyuan != null) {
				request.setAttribute("huiyuan", huiyuan);
			}
			actiontype = "update";
		}
		request.setAttribute("id", id);
		request.setAttribute("actiontype", actiontype);
		try {
			request.getRequestDispatcher("huiyuanadd.jsp").forward(request,
					response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/******************************************************
	 *********************** 数据绑定内部支持*********************
	 *******************************************************/
	public void binding() {
		String filter = "";
		//
		int pageindex = 1;
		int pagesize = 10;
		// 获取当前分页

		String accountname = request.getParameter("accountname");

		if (accountname != null)
			filter = "  where accountname like '%" + accountname + "%'  ";

		String currentpageindex = request.getParameter("currentpageindex");
		// 当前页面尺寸
		String currentpagesize = request.getParameter("pagesize");
		// 设置当前页
		if (currentpageindex != null)
			pageindex = new Integer(currentpageindex);
		// 设置当前页尺寸
		if (currentpagesize != null)
			pagesize = new Integer(currentpagesize);
		List<Huiyuan> listhuiyuan = DALBase.getPageEnity("huiyuan", filter,
				pageindex, pagesize);
		int recordscount = DALBase.getRecordCount("huiyuan",
				filter == null ? "" : filter);
		request.setAttribute("listhuiyuan", listhuiyuan);
		PagerMetal pm = new PagerMetal(recordscount);
		// 设置尺寸
		pm.setPagesize(pagesize);
		// 设置当前显示页
		pm.setCurpageindex(pageindex);
		// 设置分页信息
		request.setAttribute("pagermetal", pm);
		// 分发请求参数
		dispatchParams(request, response);
		try {
			request.getRequestDispatcher("/admin/huiyuanmanager.jsp").forward(
					request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

评论:

package com.itbaizhan.daowen.action;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.SQLQuery;
import org.hibernate.Query;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.text.MessageFormat;

import com.itbaizhan.daowen.bll.*;
import com.itbaizhan.daowen.dal.*;
import com.itbaizhan.daowen.entity.*;
import com.itbaizhan.daowen.util.DaowenUIHelper;
import com.itbaizhan.daowen.util.ExtHelper;
import com.itbaizhan.daowen.util.HibernateSessionFactory;
import com.itbaizhan.daowen.util.PagerMetal;


public class CommentAction extends PageActionBase {
	public void OnLoad() {
		String actiontype = request.getParameter("actiontype");
		System.out.println("actiontype=" + actiontype);
		if (actiontype == null)
			return ;
		
	}

	/********************************************************
	 ****************** 信息注销监听支持*****************************
	 *********************************************************/
	public void delete() {
		String id = request.getParameter("id");
		DALBase.delete("comment", " where id=" + id);
		binding();
	}

	/*************************************************************
	 **************** 保存动作监听支持******************************
	 **************************************************************/
	public void save() {
		String title = request.getParameter("title");
		
		String commentren = request.getParameter("currenthy");
		String commentcontent = request.getParameter("dcontent");
		String xtype = request.getParameter("type");
		String belongid = request.getParameter("belongid");
		
		Comment comment = new Comment();
		comment.setTitle(title == null ? "" : title);
		
		comment.setCommenttime(new Date());
		
		comment.setCommentren(commentren == null ? "" : commentren);
		comment.setCommentcontent(commentcontent == null ? "" : commentcontent);
		comment.setXtype(xtype == null ? "" : xtype);
		comment.setBelongid(belongid == null ? "" : belongid);
		DALBase.save(comment);

		 String forwardurl=request.getParameter("forwardurl");
			try {

				if (forwardurl!=null) {
					
					response.sendRedirect(SystemParam.getSiteRoot()+forwardurl);
				}
			
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}


	}

	/******************************************************
	 *********************** 内部附件支持*********************
	 *******************************************************/
	public void attachements(HttpServletRequest request,
			HttpServletResponse response, String belongid) {
		DALBase.delete("attachement", MessageFormat.format(
				" where belongid=''{0}'' and belongtable=''comment'' ",
				belongid));
		String[] photos = request.getParameterValues("fileuploaded");
		if (photos == null)
			return;
		for (int i = 0; i < photos.length; i++) {
			Attachement a = new Attachement();
			a.setType("images");
			a.setPubtime(new Date());
			a.setBelongfileldname("id");
			a.setFilename(photos[i]);
			a.setBelongid(belongid);
			a.setBelongtable("comment");
			a.setUrl(SystemParam.getSiteRoot() + "/upload/temp/"
					+ a.getFilename());
			a.setTitle(a.getFilename());
			DALBase.save(a);
		}
	}

	

	/******************************************************
	 *********************** 更新内部支持*********************
	 *******************************************************/
	public void update() {
		String id = request.getParameter("id");
		if (id == null)
			return;
		Comment comment = (Comment) DALBase
				.load(Comment.class, new Integer(id));
		if (comment == null)
			return;
		String title = request.getParameter("title");
		String commenttime = request.getParameter("commenttime");
		String commentren = request.getParameter("commentren");
		String commentcontent = request.getParameter("commentcontent");
		String xtype = request.getParameter("xtype");
		String belongid = request.getParameter("belongid");
		SimpleDateFormat sdfcomment = new SimpleDateFormat("yyyy-MM-dd");
		comment.setTitle(title);
		try {
			comment.setCommenttime(sdfcomment.parse(commenttime));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		comment.setCommentren(commentren);
		comment.setCommentcontent(commentcontent);
		comment.setXtype(xtype);
		comment.setBelongid(belongid);
		DALBase.update(comment);
		String forwardurl=request.getParameter("forwardurl");
			try {

				if (forwardurl!=null) {
					
					response.sendRedirect(SystemParam.getSiteRoot()+forwardurl);
				}
			
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}

	/******************************************************
	 *********************** 加载内部支持*********************
	 *******************************************************/
	public void load() {
		//
		String id = request.getParameter("id");
		String actiontype = "save";
		if (id != null) {
			Comment comment = (Comment) DALBase.load("comment", "where id="
					+ id);
			if (comment != null) {
				request.setAttribute("comment", comment);
			}
			actiontype = "update";
		}
		request.setAttribute("id", id);
		request.setAttribute("actiontype", actiontype);
		try {
			request.getRequestDispatcher("commentadd.jsp").forward(request,
					response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/******************************************************
	 *********************** 数据绑定内部支持*********************
	 *******************************************************/
	public void binding() {
		String filter = "";
		//
		
		
		String commentren=request.getParameter("commentren");
		
		if(commentren!=null)
			filter="  where commentren like '%" + commentren + "%'  ";
		int pageindex = 1;
		int pagesize = 10;
		// 获取当前分页
		String currentpageindex = request.getParameter("currentpageindex");
		// 当前页面尺寸
		String currentpagesize = request.getParameter("pagesize");
		// 设置当前页
		if (currentpageindex != null)
			pageindex = new Integer(currentpageindex);
		// 设置当前页尺寸
		if (currentpagesize != null)
			pagesize = new Integer(currentpagesize);
		List<Comment> listcomment = DALBase.getPageEnity("comment", filter,
				pageindex, pagesize);
		int recordscount = DALBase.getRecordCount("comment",
				filter == null ? "" : filter);
		request.setAttribute("listcomment", listcomment);
		PagerMetal pm = new PagerMetal(recordscount);
		// 设置尺寸
		pm.setPagesize(pagesize);
		// 设置当前显示页
		pm.setCurpageindex(pageindex);
		// 设置分页信息
		request.setAttribute("pagermetal", pm);
		// 分发请求参数
		dispatchParams(request, response);
		try {
			request.getRequestDispatcher("/admin/commentmanager.jsp").forward(
					request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

商品:

package com.itbaizhan.daowen.action;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.filefilter.AndFileFilter;
import org.apache.commons.io.filefilter.FalseFileFilter;
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 org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.SQLQuery;
import org.hibernate.Query;



import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.text.MessageFormat;

import com.itbaizhan.daowen.bll.*;
import com.itbaizhan.daowen.dal.*;
import com.itbaizhan.daowen.entity.*;
import com.itbaizhan.daowen.util.ExtHelper;
import com.itbaizhan.daowen.util.HibernateSessionFactory;
import com.itbaizhan.daowen.util.PagerMetal;


public class ShangpinAction extends PageActionBase {
	public void onLoad() {
		String actiontype = request.getParameter("actiontype");
		System.out.println("actiontype=" + actiontype);
		if (actiontype == null)
			return ;
	
		if(actiontype.equals("hasExist")){
			hasExist();
		}
		
	}

	private void hasExist() {
		String spno=request.getParameter("spno");
		String strres="true";
		if(DALBase.isExist("shangpin", "where spno='"+spno.trim()+"'")){
			strres="false";
		}else {
			
            strres="true";
		}
		try {
			System.out.println("商品编号存在性="+strres);
			response.getWriter().write(strres);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/********************************************************
	 ****************** 信息注销监听支持*****************************
	 *********************************************************/
	public void delete() {
		String id = request.getParameter("id");
		DALBase.delete("shangpin", " where id=" + id);
		binding();
	}

	/*************************************************************
	 **************** 保存动作监听支持******************************
	 **************************************************************/
	public void save() {
		String forwardurl = request.getParameter("forwardurl");
		String errorurl=request.getParameter("errorurl");
		String name = request.getParameter("name");
		String spno = request.getParameter("spno");
		String jiage = request.getParameter("jiage");
		String dazhe = request.getParameter("dazhe");
		String tuijian = request.getParameter("tuijian");
		String zuixin = request.getParameter("zuixin");
		String hot=request.getParameter("hot");
		String sptype = request.getParameter("sptype");
		String sptypeid = request.getParameter("sptypeid");
		String tupian = request.getParameter("tupian");
		String jieshao = request.getParameter("jieshao");
		String hyjia = request.getParameter("hyjia");
    	String pubren = request.getParameter("pubren");
		SimpleDateFormat sdfshangpin = new SimpleDateFormat("yyyy-MM-dd");
		Shangpin shangpin = new Shangpin();
		shangpin.setName(name == null ? "" : name);
		shangpin.setSpno(spno == null ? "" : spno);
		shangpin.setJiage(jiage == null ? (double) 0 : new Double(jiage));
		shangpin.setDazhe(dazhe == null ? 0 : new Integer(dazhe));
		shangpin.setTuijian(tuijian == null ? 0 : new Integer(tuijian));
		shangpin.setZuixin(zuixin == null ? 0 :new Integer( zuixin));
		shangpin.setHot(hot==null?0:new Integer(hot));
		shangpin.setSptype(sptype == null ? "" : sptype);
		shangpin.setSptypeid(sptypeid == null ? 0 : new Integer(sptypeid));
		shangpin.setTupian(tupian == null ? "" : tupian);
		shangpin.setJieshao(jieshao == null ? "" : jieshao);
		shangpin.setHyjia(hyjia == null ? 0 : new Integer(hyjia));
		
		shangpin.setPubtime(new Date());
		
		shangpin.setPubren(pubren == null ? "" : pubren);
		
		if(DALBase.isExist("shangpin", "where spno='"+spno.trim()+"'")){
			request.setAttribute("shangpin", shangpin);
			request.setAttribute("errormsg", String.format("<label class=\"error\">商品编号%1$s已经存在</label>",spno));
			
			List<Object> sptype_datasource = DALBase.getEntity("Spcategory", "");
			request.setAttribute("sptype_datasource", sptype_datasource);
			dispatchParams(request, response);
			try {
				request.getRequestDispatcher(errorurl).forward(request, response);
			} catch (ServletException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return;
		}
		
		DALBase.save(shangpin);
		
		try {
			response.sendRedirect(SystemParam.getSiteRoot()+"/admin/shangpinmanager.do?actiontype=get");
		} catch (IOException e) {
			
			e.printStackTrace();
		}
		
	}

	

	
	/******************************************************
	 *********************** 更新内部支持*********************
	 *******************************************************/
	public void update() {
		String forwardurl = request.getParameter("forwardurl");
		String errorurl=request.getParameter("errorurl");
		String id = request.getParameter("id");
		if (id == null)
			return;
		Shangpin shangpin = (Shangpin) DALBase.load(Shangpin.class,
				new Integer(id));
		if (shangpin == null)
			return;
		String name = request.getParameter("name");
		String spno = request.getParameter("spno");
		String jiage = request.getParameter("jiage");
		String dazhe = request.getParameter("dazhe");
		String tuijian = request.getParameter("tuijian");
		String zuixin = request.getParameter("zuixin");
		String hot=request.getParameter("hot");
		String sptype = request.getParameter("sptype");
		String sptypeid = request.getParameter("sptypeid");
		String tupian = request.getParameter("tupian");
		String jieshao = request.getParameter("jieshao");
		String hyjia = request.getParameter("hyjia");
		
		String pubren = request.getParameter("pubren");
		
		shangpin.setName(name);
		shangpin.setSpno(spno);
		shangpin.setJiage(jiage == null ? (double) 0 : new Double(jiage));
		shangpin.setDazhe(dazhe == null ? 0 : new Integer(dazhe));
		shangpin.setTuijian(tuijian == null ? 0 : new Integer(tuijian));
		shangpin.setZuixin(zuixin==null?0:new Integer( zuixin));
		shangpin.setHot(hot==null?0:new Integer(hot));
		shangpin.setSptype(sptype);
		shangpin.setSptypeid(sptypeid == null ? 0 : new Integer(sptypeid));
		shangpin.setTupian(tupian);
		shangpin.setJieshao(jieshao);
		shangpin.setHyjia(hyjia == null ? 0 : new Integer(hyjia));
		
		shangpin.setPubtime(new Date() );
		
		shangpin.setPubren(pubren);
		
		DALBase.update(shangpin);
		try {
			response.sendRedirect(SystemParam.getSiteRoot()+"/admin/shangpinmanager.do?actiontype=get");
		} catch (IOException e) {
			
			e.printStackTrace();
		}
		
	}

	/******************************************************
	 *********************** 加载内部支持*********************
	 *******************************************************/
	public void load() {
		//
		String id = request.getParameter("id");
		String actiontype = "save";
		dispatchParams(request, response);
		if (id != null) {
			Shangpin shangpin = (Shangpin) DALBase.load("shangpin", "where id="
					+ id);
			if (shangpin != null) {
				request.setAttribute("shangpin", shangpin);
			}
			actiontype = "update";
			request.setAttribute("id", id);
		}
		request.setAttribute("actiontype", actiontype);
		List<Object> sptype_datasource = DALBase.getEntity("Spcategory", "where isleaf=1");
		request.setAttribute("sptype_datasource", sptype_datasource);
		String forwardurl = request.getParameter("forwardurl");
		System.out.println("forwardurl=" + forwardurl);
		if (forwardurl == null) {
			forwardurl = "/admin/shangpinadd.jsp";
		}
		try {
			request.getRequestDispatcher(forwardurl).forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/******************************************************
	 *********************** 数据绑定内部支持*********************
	 *******************************************************/
	public void binding() {
		
		List<Object> sptype_datasource = DALBase.getEntity("Spcategory", "where isleaf=1");
		if(sptype_datasource!=null){
			Spcategory spcategory=new  Spcategory();
			spcategory.setId(-1);
			spcategory.setMingcheng("全部");
			spcategory.setIsleaf(1);
			sptype_datasource.add(spcategory);
		}
		request.setAttribute("sptype_datasource", sptype_datasource);
		String filter = "where 1=1 ";
		String spname = request.getParameter("name");
		if (spname != null)
			filter += "  and name like '%" +spname + "%'  ";
		
		String  sptype=request.getParameter("sptype");
		String  sptypeid=request.getParameter("sptypeid");
		System.out.println("sptypeid="+sptypeid);
		if(sptypeid!=null){
			if(!sptypeid.equals("-1"))
			   filter += "  and sptypeid=" +sptypeid ;
		}else
		if(sptypeid==null&&sptype_datasource.size()>0){
			
			filter+="  and sptypeid=" +((Spcategory)sptype_datasource.get(0)).getId() ;
		}
		int pageindex = 1;
		int pagesize = 10;
		// 获取当前分页
		String currentpageindex = request.getParameter("currentpageindex");
		// 当前页面尺寸
		String currentpagesize = request.getParameter("pagesize");
		// 设置当前页
		if (currentpageindex != null)
			pageindex = new Integer(currentpageindex);
		// 设置当前页尺寸
		if (currentpagesize != null)
			pagesize = new Integer(currentpagesize);
		List<Shangpin> listshangpin = DALBase.getPageEnity("shangpin", filter,
				pageindex, pagesize);
		int recordscount = DALBase.getRecordCount("shangpin",
				filter == null ? "" : filter);
		request.setAttribute("listshangpin", listshangpin);
		PagerMetal pm = new PagerMetal(recordscount);
		// 设置尺寸
		pm.setPagesize(pagesize);
		// 设置当前显示页
		pm.setCurpageindex(pageindex);
		// 设置分页信息
		request.setAttribute("pagermetal", pm);
		
		
		// 分发请求参数
		dispatchParams(request, response);
		String forwardurl = request.getParameter("forwardurl");
		System.out.println("forwardurl=" + forwardurl);
		if (forwardurl == null) {
			forwardurl = "/admin/shangpinmanager.jsp";
		}
		try {
			request.getRequestDispatcher(forwardurl).forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

公告:

package com.itbaizhan.daowen.action;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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 org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.SQLQuery;
import org.hibernate.Query;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.text.MessageFormat;

import com.itbaizhan.daowen.bll.*;
import com.itbaizhan.daowen.dal.*;
import com.itbaizhan.daowen.entity.*;
import com.itbaizhan.daowen.util.DaowenUIHelper;
import com.itbaizhan.daowen.util.ExtHelper;
import com.itbaizhan.daowen.util.HibernateSessionFactory;
import com.itbaizhan.daowen.util.PagerMetal;


public class NoticeAction extends PageActionBase {
	

	/********************************************************
	 ****************** 信息注销监听支持*****************************
	 *********************************************************/
	public void delete() {
		String id = request.getParameter("id");
		DALBase.delete("notice", " where id=" + id);
		binding();
	}

	/*************************************************************
	 **************** 保存动作监听支持******************************
	 **************************************************************/
	public void save() {
		String title = request.getParameter("title");
		String pubren = request.getParameter("pubren");
		String pubtime = request.getParameter("pubtime");
		
		String dcontent = request.getParameter("dcontent");
		SimpleDateFormat sdfnotice = new SimpleDateFormat("yyyy-MM-dd");
		Notice notice = new Notice();
		notice.setTitle(title == null ? "" : title);
		notice.setPubren(pubren == null ? "" : pubren);
		
		notice.setPubtime(new Date());
		
		notice.setClickcount(0);
		notice.setDcontent(dcontent == null ? "" : dcontent);
		DALBase.save(notice);
		
		try {
			response.sendRedirect(SystemParam.getSiteRoot()+"/admin/noticemanager.do?actiontype=get");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}

	/******************************************************
	 *********************** 内部附件支持*********************
	 *******************************************************/
	public void attachements(HttpServletRequest request,
			HttpServletResponse response, String belongid) {
		DALBase.delete("attachement", MessageFormat
				.format(" where belongid=''{0}'' and belongtable=''notice'' ",
						belongid));
		String[] photos = request.getParameterValues("fileuploaded");
		if (photos == null)
			return;
		for (int i = 0; i < photos.length; i++) {
			Attachement a = new Attachement();
			a.setType("images");
			a.setPubtime(new Date());
			a.setBelongfileldname("id");
			a.setFilename(photos[i]);
			a.setBelongid(belongid);
			a.setBelongtable("notice");
			a.setUrl(SystemParam.getSiteRoot() + "/upload/temp/"
					+ a.getFilename());
			a.setTitle(a.getFilename());
			DALBase.save(a);
		}
	}

	

	/******************************************************
	 *********************** 更新内部支持*********************
	 *******************************************************/
	public void update() {
		String id = request.getParameter("id");
		if (id == null)
			return;
		Notice notice = (Notice) DALBase.load(Notice.class, new Integer(id));
		if (notice == null)
			return;
		String title = request.getParameter("title");
		String pubren = request.getParameter("pubren");
		String pubtime = request.getParameter("pubtime");
		String dcontent = request.getParameter("dcontent");
		SimpleDateFormat sdfnotice = new SimpleDateFormat("yyyy-MM-dd");
		notice.setTitle(title);
		notice.setPubren(pubren);
		
		notice.setPubtime(new Date());
		
		notice.setDcontent(dcontent);
		DALBase.update(notice);
		
		try {
			response.sendRedirect(SystemParam.getSiteRoot()+"/admin/noticemanager.do?actiontype=get");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}

	/******************************************************
	 *********************** 加载内部支持*********************
	 *******************************************************/
	public void load() {
		//
		String id = request.getParameter("id");
		String actiontype = "save";
		if (id != null) {
			Notice notice = (Notice) DALBase.load("notice", "where id=" + id);
			if (notice != null) {
				request.setAttribute("notice", notice);
			}
			actiontype = "update";
		}
		request.setAttribute("id", id);
		request.setAttribute("actiontype", actiontype);
		try {
			request.getRequestDispatcher("noticeadd.jsp").forward(request,
					response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/******************************************************
	 *********************** 数据绑定内部支持*********************
	 *******************************************************/
	public void binding() {
		String filter = "";
		//
		int pageindex = 1;
		int pagesize = 10;
		
		String title = request.getParameter("title");
		if (title != null)
			filter = "  where title like '%" + title + "%'  ";
		//
		// 获取当前分页
		String currentpageindex = request.getParameter("currentpageindex");
		// 当前页面尺寸
		String currentpagesize = request.getParameter("pagesize");
		// 设置当前页
		if (currentpageindex != null)
			pageindex = new Integer(currentpageindex);
		// 设置当前页尺寸
		if (currentpagesize != null)
			pagesize = new Integer(currentpagesize);
		List<Notice> listnotice = DALBase.getPageEnity("notice", filter,
				pageindex, pagesize);
		int recordscount = DALBase.getRecordCount("notice", filter == null ? ""
				: filter);
		request.setAttribute("listnotice", listnotice);
		PagerMetal pm = new PagerMetal(recordscount);
		// 设置尺寸
		pm.setPagesize(pagesize);
		// 设置当前显示页
		pm.setCurpageindex(pageindex);
		// 设置分页信息
		request.setAttribute("pagermetal", pm);
		// 分发请求参数
		dispatchParams(request, response);
		try {
			request.getRequestDispatcher("/admin/noticemanager.jsp").forward(
					request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

写在最后

完整源码,可交流v: Code2Life2

Logo

快速构建 Web 应用程序

更多推荐