- UID
- 37537
注册时间2007-11-8
阅读权限8
最后登录1970-1-1
初入江湖
该用户从未签到
|
值得提一下的是下面这个Open,他是一个在windows的环境下打开文件一个方法。不能快平台。这是个缺陷
package cn.ityc.data;
import java.io.IOException;
public class Open ...{
public static void open(String fileName) throws IOException
...{
Runtime r = Runtime.getRuntime();
Process p = null;
String strwinapp = "excel.exe";
try
...{
p = Runtime.getRuntime().exec("cmd /c start "+fileName);
}
catch(Exception e)
...{
e.printStackTrace();
}
}
}
主要的代码就是这些。
然后我用了struts1。2来实现的
所以下面有action,form,和struts-config.xml文件
action
package cn.ityc.struts.action;
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.actions.DispatchAction;
import cn.ityc.data.Excel;
import cn.ityc.data.GetList;
public class GradeAction extends DispatchAction ...{
public ActionForward list(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) ...{
List list = GetList.getData("select * from excel");
request.getSession().setAttribute("list", list);
return mapping.findForward("showlist");
}
public ActionForward excel(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) ...{
Excel ee = new Excel();
ee.produce();
return mapping.findForward("success");
}
}
form
/**//*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package cn.ityc.struts.form;
import java.math.BigDecimal;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
/** *//**
* MyEclipse Struts
* Creation date: 11-30-2007
*
* XDoclet definition:
* @struts.form name="gradeForm"
*/
public class GradeForm extends ActionForm ...{
/**//*
* Generated fields
*/
/** *//** grade property */
private BigDecimal grade;
/** *//** course property */
private String course;
/** *//** name property */
private String name;
/**//*
* Generated Methods
*/
/** *//**
* Method validate
* @param mapping
* @param request
* @return ActionErrors
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) ...{
// TODO Auto-generated method stub
return null;
}
/** *//**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) ...{
// TODO Auto-generated method stub
}
/** *//**
* Returns the grade.
* @return String
*/
/** *//**
* Returns the course.
* @return String
*/
public String getCourse() ...{
return course;
}
/** *//**
* Set the course.
* @param course The course to set
*/
public void setCourse(String course) ...{
this.course = course;
}
/** *//**
* Returns the name.
* @return String
*/
public String getName() ...{
return name;
}
/** *//**
* Set the name.
* @param name The name to set
*/
public void setName(String name) ...{
this.name = name;
}
public BigDecimal getGrade() ...{
return grade;
}
public void setGrade(BigDecimal grade) ...{
this.grade = grade;
}
}
struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources />
<form-beans >
<form-bean name="gradeForm" type="cn.ityc.struts.form.GradeForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings >
<action
attribute="gradeForm"
input="/form/grade.jsp"
name="gradeForm"
parameter="method"
path="/grade"
scope="request"
type="cn.ityc.struts.action.GradeAction">
<forward name="success" path="/index.jsp" />
<forward name="showlist" path="/showlist.jsp" />
</action>
</action-mappings>
<message-resources parameter="cn.ityc.struts.ApplicationResources" />
</struts-config> |
|