⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 favaction.java

📁 一个简单的标签搜索.通过标签可以模糊查询数据.
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.fxe.dcl1.web.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.actions.DispatchAction;

import com.fxe.dcl1.biz.FavBiz;
import com.fxe.dcl1.biz.TagBiz;
import com.fxe.dcl1.biz.impl.FavBizImpl;
import com.fxe.dcl1.biz.impl.TagBizImpl;
import com.fxe.dcl1.web.form.FavForm;

/**
 * MyEclipse Struts Creation date: 10-16-2008
 * 
 * XDoclet definition:
 * 
 * @struts.action path="/fav" name="favForm" parameter="op" scope="request"
 *                validate="true"
 * @struts.action-forward name="toList" path="/WEB-INF/jsp/list.jsp"
 */
public class FavAction extends DispatchAction {
	/*
	 * Generated Methods
	 */

	/**
	 * Method execute
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	TagBiz tagBiz=new TagBizImpl();
	FavBiz favBiz=new FavBizImpl();
	public ActionForward toList(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		// FavForm favForm = (FavForm) form;// TODO Auto-generated method stub
		List tags=tagBiz.loadAllTags();
		request.setAttribute("tagList", tags);
		String type = request.getParameter("type");
		if (null==type || "".equals(type)){
			type = "-1";
		}
		request.setAttribute("type", type);
		List urlList=favBiz.getFav(type);
		request.setAttribute("urlList",urlList);
		return mapping.findForward("toList");
	}
	public ActionForward toAdd(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
	    
		return mapping.findForward("toAdd");
	}
	public ActionForward doAdd(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		FavForm favForm = (FavForm) form;
		//合法性验证
		ActionMessages errors = new ActionMessages();
		if (favForm.getItem().getLabel()==null 
				|| favForm.getItem().getLabel().equals("")){
			errors.add("label", new ActionMessage("errors.validate.noLabel")); 
		}
		if (favForm.getItem().getUrl()==null 
				|| favForm.getItem().getUrl().equals("")){
			errors.add("url", new ActionMessage("errors.validate.noUrl")); 
		}
		if(errors!=null&&!errors.isEmpty())
		{
			this.saveErrors(request, errors);
			return mapping.findForward("input");
		}
		favBiz.addFav(favForm.getItem());
		try {
			PrintWriter out=response.getWriter();
			out.write("<script>alert('添加成功');window.close();</script>");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	public ActionForward toCloud(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
	    List tagList=tagBiz.loadAllTags();
	    request.setAttribute("tagList",tagList);
		return mapping.findForward("toCloud");
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -