jspsmartupload如果需要,给我发信,我把包发给你[email protected],或者去bj.163.com中的jsp版看看
解决方案 »
- 获取浏览器的缩放比例
- 在线高分:求一方法,做一个类似于http://www.1rest.com这样的网页结构
- (100分)急用!JSP实现动态表格的生成及表格合并问题?
- 本人买电脑啊,谁给配制下。顶者有分!快啊!!!!!!!!!
- 在JSP中如何得到设置了代理服务器的客户端的真实IP?
- "\"是转义字符的简单问题?
- 关于Cookie的(expire)有效期限问题!在线等待!!
- jsp如何连接Access
- 保留原来框架页面,winopen打开的一个页面,然后发现session超时(需要重登陆),希望在原来的框架页面里打开登陆页面,关闭弹出窗口
- 如何共享session????有难度吧
- 关于Sql Server 2000的jdbc问题(高分相增)
- 找北京在校大学生兼职,一个月,擅长Jsp的!
<td width="24%" align="right" height="12" bgcolor="#FFFFFF">上传图片:</td>
<td width="76%" height="12" bgcolor="#FFFFFF"><input type="file" name="File1" size="20"></td>
</tr>加进去就可以啦!呵呵!
至于获取嘛!呵呵!加入下面代码!
<%
// Variables
int count=0;
// 初始化
mySmartUpload.initialize(pageContext);
//允许上传文件类型
//mySmartUpload.setAllowedFilesList("gif,GIF,jpg,JPG");
//允许上传文件的大小
//mySmartUpload.setMaxFileSize(20000);
//文件上传
mySmartUpload.upload();
//选择多个文件
java.sql.Statement stmt=newsbean.conn.createStatement();
int intGif=0;
String sql=new String();
for (int i=0;i<mySmartUpload.getFiles().getCount();i++)
{
// Retreive the current file
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
sql="select * from content order by id desc limit 1";
// Save it only if this file exists
if (!myFile.isMissing())
{
//另外保存文件
try{
String sqllock="lock tables content write"; //加锁
stmt.executeUpdate(sqllock);
}catch(java.sql.SQLException ex){
stmt.close();
newsbean.conn.close();
%>
<script language="javascript">
alert("操作失败!");
history.back();
</script>
<%
out.close();
}
java.sql.ResultSet rs=stmt.executeQuery(sql);
if(!rs.next()){
intGif=1;
}else{
StringBuffer strGif=new StringBuffer("");
String temp=rs.getString("up_photo");
strGif.append(temp.substring(4,(temp.length()-4)));
temp=new String(strGif);
intGif=java.lang.Integer.parseInt(temp);
intGif=intGif+1; }
//}
String strFile="NEWS"+intGif+".gif";
int size=myFile.getSize();
String image=myFile.getContentType();
if(!(image.trim().equals("image/gif") || image.trim().equals("image/pjpeg")))
{
stmt.close();
newsbean.conn.close();
%>
<script language="javascript">
alert("图片文件必须为gif或jpg文件!");
</script>
<script language="javascript">
history.back();
</script>
<%
out.close();
}
if(size>40000)
{
stmt.close();
newsbean.conn.close();
%>
<script language="javascript">
alert("图片文件大小不能超过40K");
</script>
<script language="javascript">
history.back();
</script>
<%
out.close();
}
//上传
myFile.saveAs("/news/image/"+strFile,mySmartUpload.SAVE_VIRTUAL); }
}
********PictureFile.jsp***********************************<%@ taglib uri="/struts-bean" prefix="bean" %>
<%@ taglib uri="/struts-html" prefix="html" %>
<%@ taglib uri="/struts-template" prefix="template" %>
<%@ taglib uri="/struts-logic" prefix="logic" %>
<%@ taglib uri="/struts-html" prefix="html" %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE>Product File</TITLE>
</HEAD>
<BODY>
<logic:present name="FileInfo" >
<form action="/ProductFile" name=ProductFile enctype="multipart/form-data" method="post">
<TABLE cellSpacing=1 cellPadding=1 border=0 width=80%>
<TABLE cellSpacing=1 cellPadding=1 border=1 width=100%>
<TR>
<TD align=middle width="20%">Filename</TD>
</TR>
<TR>
<TD align=right width="20%">
<html:file name="FileInfo" property="pictureData1" title="Browse File" />
</TD>
</TR>
</TABLE>
<BR><P>
<TABLE cellSpacing=0 cellPadding=0 border=0 width=100%>
<TR>
<TD colspan=4 align=right>
<INPUT type=button name="btnSave" value=Update onclick="doAction('Update');">
</TD>
</TR>
</TABLE>
</TABLE>
</form>
</logic:present></BODY>
</HTML>
<SCRIPT LANGUAGE=JavaScript>
<!--function doAction(type){
if(type=='Update'){
str = "ProductFile.do?mode=update";
window.ProductFile.action = str;
window.ProductFile.submit();
return true;
}
return false;
}
//-->
</SCRIPT>
************************PictureForm.java***********************
package Picture.form;import org.apache.struts.action.ActionForm;
import org.apache.struts.upload.FormFile;
import java.io.InputStream;
public class PictureForm extends ActionForm{
transient protected FormFile pictureData1 = null;
public FormFile getPictureData1(){
return this.pictureData1;
}
public void setPictureData1(FormFile pData){
this.pictureData1 = pData;
}
public PictureForm() {}
}
*************************************PictureAction.java**************************
package Picture.action;import java.util.Vector;
import java.util.Map;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.upload.FormFile;
import java.io.InputStream;public class PictureAction extends Action{ public PictureAction() {
} public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws IOException,ServletException
{
String mode=null;
mode= request.getParameter("mode");
if (mode.equals("update"))
{
UpdateFileDetails(request,form);
}
return(mapping.findForward("success"));
} private void UpdateFileDetails(HttpServletRequest request, ActionForm form){ try
{
ProdFileForm fForm = (ProdFileForm)form;
FormFile small=fForm.getPictureData1();
byte[] smallStream=getFileContent(small);
}
catch(Exception e)
{
System.err .println(e.getMessage() );
}
}
private static byte[] getFileContent(FormFile file) throws IOException
{
InputStream in=file.getInputStream();
int count=in.available();
byte[] ret=new byte[count];
in.read(ret);
return ret;
}
}
*****************************weblogic 的配置文件***********************
**************\web-inf\struts-config.xml*********************
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd"><struts-config>
<form-beans>
<form-bean name="ProdFileForm"
type="com.bexcom.bexcatalog.web.product.form.ProdFileForm"/>
</form-beans>
<action-mappings>
<action path="/Picture"
type="PictureAction"
name="PictureForm"
scope="request"
validate="false">
<forward name="success" path="/product/ProductFile.jsp"/>
</action>
</action-mappings>
</struts-config>**************\web-inf\web.xml*********************
(这个文件不用写了,下载Struts的包时,也就是那个样子,不用怎么改就可以用了)