📄 getcataction.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.shopping.struts.action.category;
import java.io.IOException;
import java.util.List;
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 com.shopping.dao.UnifyDao;
import com.shopping.factory.DAOFactory;
import com.shopping.vo.Category;
/**
* MyEclipse Struts
* Creation date: 05-01-2008
*
* XDoclet definition:
* @struts.action validate="true"
*/
public class GetCatAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
int id = Integer.parseInt(request.getParameter("id"));
System.out.println(id);
UnifyDao catDao = null;
try {
catDao = (UnifyDao) DAOFactory
.getBean("com.shopping.dao.imp.CatDaoImp");
} catch (InstantiationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalAccessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
List<Category> childs = catDao.getTable(id) ;
System.out.println(childs.size());
StringBuffer buf = new StringBuffer();
buf.append("document.Form1.child.length = " + (childs.size()+1) + ";\n");
buf.append("document.Form1.child.options[0].value = '-1';\n");
buf.append("document.Form1.child.options[0].text = '请选择!';\n");
buf.append("document.Form1.child.selectedIndex = 0;\n");
for(int i=0; i<childs.size(); i++) {
Category c = childs.get(i);
buf.append("document.Form1.child.options[" + (i+1) + "].value = '" + c.getId() + "';\n");
buf.append("document.Form1.child.options[" + (i+1) + "].text = '" + c.getName() + "';\n");
}
response.setContentType("text/html;charset=gbk");
response.setHeader("Cache-Control", "no-store"); //HTTP1.1
response.setHeader("Pragma", "no-cache"); //HTTP1.0
response.setDateHeader("Expires", 0); //prevents catching at proxy server
try {
response.getWriter().write(buf.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -