一、上传 操作步骤
1.下载:struts2框架支持下载上传。
2.spring支持clob的上传下载:。
3.一般综合使用。
4.ssh三大框架,主流市场。
1,上传和下载到数据库的字符流 clob类型
public String uploadTemplate() throws Exception{
HttpServletRequest request = this.getRequest();
MultiPartRequestWrapper wrapper = (MultiPartRequestWrapper) request;
String id = request.getParameter("uploadId");
File[] files = wrapper.getFiles("Filedata");
File f = files[0];
InputStreamReader read = new InputStreamReader(new FileInputStream(f),"utf-8");
BufferedReader reader=new BufferedReader(read);
int ch=reader.read();
StringBuffer buffer=new StringBuffer();
while(ch!=-1){ //读取成功
buffer.append((char)ch);
ch=reader.read();
}
String clob = buffer.append((char)ch).toString();
System.out.println(clob);
//3、关闭流
reader.close();
cmSysService.uploadTemplate(id, clob);
return Constant.SUCCESS;
}
二、下载 操作步骤
@SuppressWarnings("unused")
public String downLoadTemplate() throws Exception{
String id=this.getRequest().getParameter("templateId");
//获取模板信息
String data="";;//string 类型
FbDocTemplate docTemplate = cmSysService.getDocTemplate(id);
String name1 = docTemplate.getTemplateName();
PrintWriter writer = this.getResponse().getWriter();
// this.getResponse().setCharacterEncoding("UTF-8");//0331231213962FE26F866
this.getResponse().setHeader("Content-Disposition",
"attachment; " + this.encodeFileName(getRequest(), name1+".text"));
//this.getResponse().setContentType("application/msword;charset=GBK");
data = new String(docTemplate.getTemplateContent().getBytes("GBK"),"GBK");
try{
writer.write(data);
}catch(Exception e){
throw e;
}finally{
if (writer != null) {
writer.flush();
writer.close();
}
}
return null
No. |
方法 |
类型 |
描述 |
1 |
Int executeUpdate(String sql)throws SQLException |
普通 |
执行数据库更新的SQL语句,例如:INSERT、UPDATE、DELETE等语句,返回更新的记录数 |
2 |
ResultSet executeQuery(String sql)throws SQLException |
普通 |
执行数据库查询操作,返回一个结果集对象 |
3 |
void addBatch(String sql)throws SQLException |
普通 |
增加一个待执行的SQL语句 |
4 |
int[] executeBatch()throws SQLException |
普通 |
批量执行SQL语句 |
5 |
void close()throws SQLException |
普通 |
关闭Statement操作 |
6 |
Boolean execute(String sql)throws SQLException |
普通 |
执行SQL语句 |
public class Info {
private String id;
private String pass;
private int age;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
注:
(1)下载详细了解一下关于LOB类型的数据,有利于长期有效的发展。
(2)平时详细了解一下struts2框架,可以系统学习一下其原理,以便于更深入的理解。
一、上传 操作步骤
1.下载:struts2框架支持下载上传。
2.spring支持clob的上传下载:。
3.一般综合使用。
4.ssh三大框架,主流市场。
1,上传和下载到数据库的字符流 clob类型
public String uploadTemplate() throws Exception{
HttpServletRequest request = this.getRequest();
MultiPartRequestWrapper wrapper = (MultiPartRequestWrapper) request;
String id = request.getParameter("uploadId");
File[] files = wrapper.getFiles("Filedata");
File f = files[0];
InputStreamReader read = new InputStreamReader(new FileInputStream(f),"utf-8");
BufferedReader reader=new BufferedReader(read);
int ch=reader.read();
StringBuffer buffer=new StringBuffer();
while(ch!=-1){ //读取成功
buffer.append((char)ch);
ch=reader.read();
}
String clob = buffer.append((char)ch).toString();
System.out.println(clob);
//3、关闭流
reader.close();
cmSysService.uploadTemplate(id, clob);
return Constant.SUCCESS;
}
二、下载 操作步骤
@SuppressWarnings("unused")
public String downLoadTemplate() throws Exception{
String id=this.getRequest().getParameter("templateId");
//获取模板信息
String data="";;//string 类型
FbDocTemplate docTemplate = cmSysService.getDocTemplate(id);
String name1 = docTemplate.getTemplateName();
PrintWriter writer = this.getResponse().getWriter();
// this.getResponse().setCharacterEncoding("UTF-8");//0331231213962FE26F866
this.getResponse().setHeader("Content-Disposition",
"attachment; " + this.encodeFileName(getRequest(), name1+".text"));
//this.getResponse().setContentType("application/msword;charset=GBK");
data = new String(docTemplate.getTemplateContent().getBytes("GBK"),"GBK");
try{
writer.write(data);
}catch(Exception e){
throw e;
}finally{
if (writer != null) {
writer.flush();
writer.close();
}
}
return null
No. |
方法 |
类型 |
描述 |
1 |
Int executeUpdate(String sql)throws SQLException |
普通 |
执行数据库更新的SQL语句,例如:INSERT、UPDATE、DELETE等语句,返回更新的记录数 |
2 |
ResultSet executeQuery(String sql)throws SQLException |
普通 |
执行数据库查询操作,返回一个结果集对象 |
3 |
void addBatch(String sql)throws SQLException |
普通 |
增加一个待执行的SQL语句 |
4 |
int[] executeBatch()throws SQLException |
普通 |
批量执行SQL语句 |
5 |
void close()throws SQLException |
普通 |
关闭Statement操作 |
6 |
Boolean execute(String sql)throws SQLException |
普通 |
执行SQL语句 |
public class Info {
private String id;
private String pass;
private int age;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
注:
(1)下载详细了解一下关于LOB类型的数据,有利于长期有效的发展。
(2)平时详细了解一下struts2框架,可以系统学习一下其原理,以便于更深入的理解。