- 浏览: 151319 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
hx0637:
楼主!小弟要面临面试了,能否指导下小弟?
面试 深圳一家公司的 -
kljismi:
你好,我现在正在开这项目的代码,但是我不明白@Privileg ...
权限管理模块分析 -
yzhw:
终于找到了
ImageSizer.java -
sunloveny:
国
struts国际化 -
jackotty:
谢谢楼主的分享
struts validator验证框架
DrpExceptionHandler.java
LoginActionForm.java
ItemActionForm.java
BaseAction.java
ChangeLanguageAction.java
ItemAction.java
LoginAction.java
package com.bjsxt.drp.web.util; import org.apache.struts.action.ExceptionHandler; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.Globals; 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.config.ExceptionConfig; import com.bjsxt.drp.business.util.AppException; import com.bjsxt.drp.business.util.AppException; /** * 个性化异常处理类 */ public class DrpExceptionHandler extends ExceptionHandler { public ActionForward execute( Exception ex, ExceptionConfig ae, ActionMapping mapping, ActionForm formInstance, HttpServletRequest request, HttpServletResponse response) throws ServletException { if (!(ex instanceof AppException )) { return super.execute(ex, ae, mapping, formInstance, request, response); } AppException errCodeEx =(AppException) ex; ActionForward forward = null; ActionMessage error = null; String property = null; // Build the forward from the exception mapping if it exists // or from the form input if (ae.getPath() != null) { forward = new ActionForward(ae.getPath()); } else { forward = mapping.getInputForward(); } //----------处理个性化异常------------- AppException ece =(AppException) ex; String errorCode =ece.getErrorCode(); error = new ActionMessage(errorCode, ece.getArgs()); property = error.getKey(); //----------------------------------- logException(ex); // Store the exception request.setAttribute(Globals.EXCEPTION_KEY, ex); storeException(request, property, error, forward, ae.getScope()); return forward; } }
LoginActionForm.java
package com.bjsxt.drp.web.itemmgr.forms; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; /** * 收集表单数据的ActionForm,ActionForm中的属性必须与html中表单中的name名称一致 * @author Administrator * */ public class LoginActionForm extends ActionForm { private String username; private String password; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
ItemActionForm.java
package com.bjsxt.drp.web.itemmgr.forms; import org.apache.struts.action.ActionForm; import org.apache.struts.upload.FormFile; public class ItemActionForm extends ActionForm { //物料代码 private String itemNo; //物料名称 private String itemName; //规格 private String spec; //型号 private String pattern; //类型 private String categoryId; //单位 private String unitId; //收集物料代码,主要用户批量删除 private String[] selectFlag; //查询条件 private String clientIdOrName; //上传的文件名 private FormFile fileName; //第几页 private int pageNo; //每页多少条 private int pageSize; public String getItemName() { return itemName; } public void setItemName(String itemName) { this.itemName = itemName; } public String getItemNo() { return itemNo; } public void setItemNo(String itemNo) { this.itemNo = itemNo; } public String getPattern() { return pattern; } public void setPattern(String pattern) { this.pattern = pattern; } public String getSpec() { return spec; } public void setSpec(String spec) { this.spec = spec; } public String[] getSelectFlag() { return selectFlag; } public void setSelectFlag(String[] selectFlag) { this.selectFlag = selectFlag; } public String getClientIdOrName() { return clientIdOrName; } public void setClientIdOrName(String clientIdOrName) { this.clientIdOrName = clientIdOrName; } public String getCategoryId() { return categoryId; } public void setCategoryId(String categoryId) { this.categoryId = categoryId; } public String getUnitId() { return unitId; } public void setUnitId(String unitId) { this.unitId = unitId; } public FormFile getFileName() { return fileName; } public void setFileName(FormFile fileName) { this.fileName = fileName; } public int getPageNo() { return pageNo; } public void setPageNo(int pageNo) { this.pageNo = pageNo; } public int getPageSize() { return pageSize; } public void setPageSize(int pageSize) { this.pageSize = pageSize; } }
BaseAction.java
package com.bjsxt.drp.web.itemmgr.actions; 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.actions.DispatchAction; public class BaseAction extends DispatchAction { @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { if (request.getSession().getAttribute("user") == null) { return mapping.findForward("index"); } return super.execute(mapping, form, request, response); } }
ChangeLanguageAction.java
package com.bjsxt.drp.web.itemmgr.actions; import java.util.Locale; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.Globals; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; public class ChangeLanguageAction extends Action { public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String lan = request.getParameter("lan"); Locale currentLocale = null; if ("en".equals(lan)) { currentLocale = new Locale("en", "US"); }else if ("zh".equals(lan)) { currentLocale = new Locale("zh", "CN"); } request.getSession().setAttribute(Globals.LOCALE_KEY, currentLocale); return mapping.findForward("success"); } }
ItemAction.java
package com.bjsxt.drp.web.itemmgr.actions; import java.io.FileOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.beanutils.BeanUtils; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.upload.FormFile; import com.bjsxt.drp.business.itemmgr.manager.ItemManager; import com.bjsxt.drp.business.itemmgr.model.Item; import com.bjsxt.drp.business.itemmgr.model.ItemCategory; import com.bjsxt.drp.business.itemmgr.model.ItemUnit; import com.bjsxt.drp.business.util.PageModel; import com.bjsxt.drp.web.itemmgr.forms.ItemActionForm; /** * 统一处理所有的请求 * @author Administrator * */ public class ItemAction extends BaseAction { private ItemManager itemManager; private String uploadPath; /** * 如果没有传递任何标识参数(如command参数),则默认调用unspecified方法 */ protected ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("ItemAction=>>unspecified()"); ActionForward listActionForward = new ActionForward("/index.jsp", true); return listActionForward; } /** * 添加物料 * * @param mapping * @param form * @param request * @param response * @return * @throws Exception */ public ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { //获取从页面表单中提交过来的值 ItemActionForm iaf = (ItemActionForm)form; //创建Item实体对象,并将ActionForm中的内容设置到Item对象中 Item item = new Item(); //将属性值从ItemActionForm对象拷贝到Item对象 BeanUtils.copyProperties(item, iaf); //设置ItemCategory ItemCategory ic = new ItemCategory(); ic.setId(iaf.getCategoryId()); item.setCategory(ic); //设置itemUnit ItemUnit iu = new ItemUnit(); iu.setId(iaf.getUnitId()); item.setUnit(iu); //调用业务逻辑操作 itemManager.addItem(item); ActionForward af = new ActionForward("item.do?command=list&pageNo=" + iaf.getPageNo() + "&pageSize=" + iaf.getPageSize(), true); return af; } /** * 删除物料 * * @param mapping * @param form * @param request * @param response * @return * @throws Exception */ public ActionForward del(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { //获取从页面表单中提交过来的值 ItemActionForm iaf = (ItemActionForm)form; //调用业务逻辑操作 itemManager.deleteItem(iaf.getSelectFlag()); ActionForward af = new ActionForward("item.do?command=list&pageNo=" + iaf.getPageNo() + "&pageSize=" + iaf.getPageSize(), true); return af; } /** * 根据物料代码查询需要修改的物料 * * @param mapping * @param form * @param request * @param response * @return * @throws Exception */ public ActionForward modifyDetail(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { //获取从页面表单中提交过来的值 ItemActionForm iaf = (ItemActionForm)form; //调用业务逻辑操作 Item item = itemManager.findItemById(iaf.getItemNo()); //将查询结果放到request中 request.setAttribute("item", item); return mapping.findForward("modify_detail"); } /** * 修改物料 * * @param mapping * @param form * @param request * @param response * @return * @throws Exception */ public ActionForward modify(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { //获取从页面表单中提交过来的值 ItemActionForm iaf = (ItemActionForm)form; //创建Item实体对象,并将ActionForm中的内容设置到Item对象中 Item item = new Item(); //将属性值从ItemActionForm对象拷贝到Item对象 BeanUtils.copyProperties(item, iaf); //设置ItemCategory ItemCategory ic = new ItemCategory(); ic.setId(iaf.getCategoryId()); item.setCategory(ic); //设置itemUnit ItemUnit iu = new ItemUnit(); iu.setId(iaf.getUnitId()); item.setUnit(iu); //调用业务逻辑操作 itemManager.modifyItem(item); ActionForward af = new ActionForward("item.do?command=list&pageNo=" + iaf.getPageNo() + "&pageSize=" + iaf.getPageSize(), true); return af; } /** * 根据物料代码查询物料 * * @param mapping * @param form * @param request * @param response * @return * @throws Exception */ public ActionForward findDetail(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { //获取从页面表单中提交过来的值 ItemActionForm iaf = (ItemActionForm)form; //调用业务逻辑操作 Item item = itemManager.findItemById(iaf.getItemNo()); //将查询结果放到request中 request.setAttribute("item", item); return mapping.findForward("find_detail"); } /** * 查询全部物料 * * @param mapping * @param form * @param request * @param response * @return * @throws Exception */ public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { //获取从页面表单中提交过来的值 ItemActionForm iaf = (ItemActionForm)form; //调用业务逻辑操作 PageModel pageModel = itemManager.findAllItem(iaf.getPageNo(), iaf.getPageSize(), iaf.getClientIdOrName()); //将查询结果放到request中 request.setAttribute("pagemodel", pageModel); return mapping.findForward("list_success"); } /** * upload页面详细信息 * * @param mapping * @param form * @param request * @param response * @return * @throws Exception */ public ActionForward uploadDetail(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { //获取从页面表单中提交过来的值 ItemActionForm iaf = (ItemActionForm)form; //调用业务逻辑操作 Item item = itemManager.findItemById(iaf.getItemNo()); //将查询结果放到request中 request.setAttribute("item", item); return mapping.findForward("upload_detail"); } /** * 上传图片 * * @param mapping * @param form * @param request * @param response * @return * @throws Exception */ public ActionForward upload(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { //获取从页面表单中提交过来的值 ItemActionForm iaf = (ItemActionForm)form; FormFile myFile = iaf.getFileName(); if(myFile != null){ //将上传的文件流保存到磁images/item下 //String realPath = request.getContextPath().getRealPath("/images/item"); //System.out.println("realpath" + ); //FileOutputStream fos = new FileOutputStream("C:\\apache-tomcat-5.5.17\\webapps\\struts_training_itemmgr\\images\\item\\"+iaf.getItemNo() + ".gif"); FileOutputStream fos = new FileOutputStream(this.uploadPath + iaf.getItemNo() + ".gif"); fos.write(myFile.getFileData()); fos.flush(); fos.close(); } ActionForward af = new ActionForward("item.do?command=list&pageNo=" + iaf.getPageNo() + "&pageSize=" + iaf.getPageSize(), true); return af; } public void setItemManager(ItemManager itemManager) { this.itemManager = itemManager; } public void setUploadPath(String uploadPath) { this.uploadPath = uploadPath; } }
LoginAction.java
package com.bjsxt.drp.web.itemmgr.actions; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.beanutils.PropertyUtils; 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.bjsxt.drp.web.itemmgr.forms.LoginActionForm; /** * 用户登录Action * @author Administrator * */ public class LoginAction extends Action { @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { LoginActionForm laf = (LoginActionForm)form; String username = laf.getUsername(); String password = laf.getPassword(); if ("admin".equals(username) && "admin".equals(password)) { request.getSession().setAttribute("user", "admin"); return mapping.findForward("sucess"); }else { return mapping.findForward("index"); } } }
发表评论
-
ssh_training_itemmgr jsp
2008-12-29 19:01 1201index.jsp <%@ page languag ... -
src\com\bjsxt\drp\business\util
2008-12-29 17:32 1146AppException.java package com. ... -
ssh_training_itemmgr 04
2008-12-29 17:28 752DataDict.java package com.bjs ... -
ssh_training_itemmgr 02
2008-12-29 17:11 1026MessageResources.properties 引 ... -
ssh_training_itemmgr 01
2008-12-29 16:58 776applicationContext-actions.xml ... -
采用声明式事务
2008-12-29 15:08 779采用声明式事务 1、声明式事务配置 * 配置Session ... -
采用编程式事务
2008-12-29 13:27 981采用编程式事务 1、getCurrentSession()与 ... -
spring+struts的集成(第二种集成方案)
2008-12-29 12:40 770spring+struts的集成(第二种集成方案) 原理:将业 ... -
spring+struts的集成(第一种集成方案)
2008-12-29 12:26 750spring+struts的集成(第一种集成方案) 原理:在A ... -
spring_dynamic_proxy
2008-12-29 00:38 742SecurityHandler.java package c ... -
AOP4
2008-12-29 00:24 694spring对AOP的支持 1、如果目标对象实现了接口,默认 ... -
AOP3
2008-12-29 00:17 702spring对AOP的支持 Aspect默认情况下不用实现 ... -
AOP2
2008-12-29 00:11 927spring对AOP的只是(采用配置文件的方式) 1、sp ... -
AOP1
2008-12-29 00:08 699spring对AOP的只是(采用Annotation的方式) ... -
spring_static_proxy
2008-12-29 00:01 760UserManager.java package com.b ... -
根据类型自动装配
2008-12-28 23:55 709引用<?xml version="1.0&qu ... -
根据名称自动装配
2008-12-28 23:53 741applicationContext-beans.xml 引 ... -
spring_scope
2008-12-28 23:42 1018spring Bean的作用域: scope可以取值: ... -
spring_injection
2008-12-28 23:14 5561、spring的普通属性注入 参见:spring文档3. ... -
DYNAMIC PROXY
2008-12-24 23:53 797package com.bjsxt.spring; ...
相关推荐
这个"ssh_training_itemmgr.zip"压缩包很可能是提供了一个SSH框架整合的实际项目示例,帮助开发者理解和学习如何在实际应用中运用这些技术。 **Struts** 是一个基于MVC设计模式的Java Web框架,主要用于控制应用...
SSH_Test.rar_C ssh_C#ssh_C++ ssh_C++ SSH_libssh2库是一个针对C、C#和C++编程语言的SSH实现示例,特别提到了libssh2库的使用。在Visual Studio 2010环境下,这个压缩包提供了通过SSH进行文件上传的功能。接下来,...
ssh_do all_list执行命令,需要修改脚本“node_list”和集群操作命令即可,执行样例如下:ssh ssh_do_all_list.sh "cat /etc/hosts
SSH(Secure Shell)是一种网络协议,用于在不安全的网络上提供安全的远程登录和其他服务。在QT(一个跨平台的C++图形用户界面应用程序开发框架)中集成SSH功能,可以实现与远程服务器的安全交互,比如执行Linux命令...
标题中的"ssh_test.rar_ssh_ssh_test"可能是指一个与SSH(Secure Shell)相关的项目或教程,其中包含了"ssh_test"的实例代码。SSH是一种网络协议,用于安全地远程登录到服务器,执行命令和传输数据。它在IT行业中...
标题"SSH.rar_myeclipse ssh_ssh_ssh myeclipse_ssh2_ssh2 Myeclipse"表明这是一个关于SSH配置和MyEclipse集成的资源包,可能包含了SSH框架在MyEclipse中的配置教程,以及SSH2(更安全的SSH版本)的相关资料。...
SSH_province_sql.rar_SSH_province_sql_ajax_dwr_ssh_ssh_ajax这个标题暗示了这是一个与SSH框架(Struts2、Spring、Hibernate)结合DWR(Direct Web Remoting)实现的项目,主要涉及到了省市县三级联动的数据处理,...
固定资产管理系统SSH_JSP_MySql(源码+数据库sql+lun文+视频齐全)固定资产管理系统SSH_JSP_MySql(源码+数据库sql+lun文+视频齐全)固定资产管理系统SSH_JSP_MySql(源码+数据库sql+lun文+视频齐全)固定资产管理系统SSH_...
ssh_known_hosts, cookbook ssh_known_hosts的开发库 ssh_known_hosts-cookbook Chef向添加主机和密钥的/etc/ssh/ssh_known_hosts 文件公开资源和默认配方,已知主机的public 键的全局文件。使用键类型和ohai数据...
标签"java_ssh ssh ssh_源码"进一步确认了这是关于Java语言实现SSH功能的源代码,强调了SSH的多次提及,可能意味着源码中包含了多个SSH相关模块或者示例。 在压缩包子文件的文件名称列表中,"www.pudn.com.txt"可能...
4.7javaEE_SSH_MySqL基于SSH的医院在线挂号(源码+数据库sql+lun文+视频齐全);javaEE_SSH_MySqL基于SSH的医院在线挂号(源码+数据库sql+lun文+视频齐全);javaEE_SSH_MySqL基于SSH的医院在线挂号(源码+数据库sql+lun...
javaEE_SSH_MVC_MySql动漫论坛的设计与实现(源码+数据库sql+lun文+视频齐全)javaEE_SSH_MVC_MySql动漫论坛的设计与实现(源码+数据库sql+lun文+视频齐全)javaEE_SSH_MVC_MySql动漫论坛的设计与实现(源码+数据库sql+...
javaEE_SSH_oracle土地档案管理系统(源码+数据库sql+lun文+视频齐全)javaEE_SSH_oracle土地档案管理系统(源码+数据库sql+lun文+视频齐全)javaEE_SSH_oracle土地档案管理系统(源码+数据库sql+lun文+视频齐全)javaEE_...
JuiceSSH_2.1.4.apk
SSH(Struts、Spring、Hibernate)是Java开发中常见的三个框架的组合,广泛应用于企业级应用的开发。这个名为"ssh_2.rar"的压缩包文件包含了一个基于SSH的项目源码,适合在MyEclipse集成开发环境中运行和学习。 **...
javaEE_SSH_SQLServer商品供应管理系统(源码+数据库sql+lun文+视频齐全)javaEE_SSH_SQLServer商品供应管理系统(源码+数据库sql+lun文+视频齐全)javaEE_SSH_SQLServer商品供应管理系统(源码+数据库sql+lun文+视频齐全...
javaEE_SSH_mysql百货中心供应链管理系统(源码+数据库sql+lun文+视频齐全)javaEE_SSH_mysql百货中心供应链管理系统(源码+数据库sql+lun文+视频齐全)javaEE_SSH_mysql百货中心供应链管理系统(源码+数据库sql+lun文+...
"淘宝发货__ssh__网上商城(ssh_eshop)__sqlserver.zip" 这个标题表明我们正在处理一个与网上商城系统相关的压缩文件。"ssh"通常指的是Struts2、Spring和Hibernate这三个Java开发框架的组合,它们在Web应用开发中广泛...
在IT行业中,SSH(Secure Shell)是一种用于在网络之间安全地执行命令、传输数据以及管理远程系统的网络协议。OpenSSH是SSH协议的开源实现,而OpenSSL则是一个强大的安全套接层(SSL)和传输层安全(TLS)协议库。...