楼主的名跟我的好像哦,呵呵
好像struts有吧
自己写也行,汉字解决挺麻烦的。
好像struts有吧
自己写也行,汉字解决挺麻烦的。
解决方案 »
- 大家来讨论讨论JDK下一个版本也就是JDK 8.0会添加什么重磅功能呢?
- 求达人帮忙解决tomcat+oracle+jsp的用尽的ResultSet现象
- 一个表单多个提交按钮怎么处理?
- java实现网络存储
- 求 jsp 图片存入oracle blob
- 小弟刚开始从事WEB开发,是看书为主还是看论坛,请各位哥哥给点意见
- 谁能告诉我,application server,web container,jvm三者到底是什么关系???
- 请教:在jsp里面如何才能引用我自己定义的java类?急!!! 谢谢了!!!
- JSP登陆后用户名显示问题!在线等!急!!急!
- 再问:如何将multiple select的选中内容读到bean
- jsp 中 2中引用java 类的区别
- jsp+java问题。
<%@ page contentType="text/html; charset=gb2312"%>
<%@ include file="/DataIni/DataOpen.jsp"%>
<%@ include file="/ScriptLib/Init.jsp"%>
<%
String strItemID,strItemName;
strItemID=request.getParameter("ID");
strItemName=request.getParameter("ItemName");
if(strItemID==null)
{
response.sendRedirect("/System/Index.jsp");
}
String strCategory="";
String strCategoryExtend="";
%>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
<link rel="stylesheet" type="text/css" href="/StyleLib/Default_Style_Sheet.css">
<script>
function GeneralSubmit(TypeValue,Id)
{
GeneralForm.TypeValue.value=TypeValue;
GeneralForm.RecordId.value=Id;
GeneralForm.submit();
}
function ShowGeneral(Id,Type)
{
var hwnd=window.open('','','');
switch(Type)
{
case "image/*":
hwnd.document.write("<Img src='/System/GeneralSystem/Show.jsp?Id="+Id+"' border=0></a>");
break;
case "audio/*":
hwnd.document.write("<BgSound src='/System/GeneralSystem/Show.jsp?Id="+Id+"' border=0>");
break;
case "video/*":
hwnd.document.write("<Img dynsrc='/System/GeneralSystem/Show.jsp?Id="+Id+"' border=0></a>");
break;
case "application/msword":
hwnd.location.href="/System/GeneralSystem/Show.jsp?Id="+Id;
break;
case "application/vnd.ms-excel":
hwnd.location.href="/System/GeneralSystem/Show.jsp?Id="+Id;
break;
default:
hwnd.location.href="/System/GeneralSystem/Show.jsp?Id="+Id;
break;
}
}
</script>
</head><body>
<%@ include file="/TemplateLib/Head.jsp"%>
<center>
<form action="Result.jsp" method="post" name="GeneralForm" enctype="multipart/form-data">
<input type="hidden" name="TypeValue" size="10" value="">
<input type="hidden" name="RecordId" size="10" value="">
<input type="hidden" name="ItemId" size="10" value="<%=strItemID%>">
<table border="0" cellpadding="0" cellspacing="0" width="80%">
<tr>
<td width="10%" class="TdClassHead"><%=strItemName%></td>
</tr>
</table>
<br>
<table border="0" width="80%" cellspacing="0" cellpadding="0">
<tr>
<td width="10%" class="TdClassLow"><%=strItemName%></td>
<td width="20%" class="TdClassLow">详细分类</td>
<td width="20%" class="TdClassLow">详细内容</td>
<td width="40%" class="TdClassLow">媒体文件</td>
<td width="10%" class="TdClassLow">执行操作</td>
</tr>
<tr>
<td width="10%" class="TdClassHigh"><input name="Subject" size="10" value=""></td>
<td width="20%" class="TdClassHigh">
<select name="Category" size=1 style="width:80%">
<option value="<%=strItemName%>">--请选择--</option>
<%
odbcQuery="select distinct Category from GeneralSystem where ItemID='"+strItemName+"'";
odbcRsExtend=odbcStmtExtend.executeQuery(odbcQuery);
while(odbcRsExtend.next())
{
strCategoryExtend=odbcRsExtend.getString("Category");
%>
<option value="<%=strCategoryExtend%>"><%=strCategoryExtend%></option>
<%
}
odbcRsExtend.close();
%>
</select>
<script>
function AddCategory()
{
var m_Category="";
m_Category=window.prompt("请输入详细分类","");
if(m_Category!="")
{
GeneralForm.Category.length=GeneralForm.Category.length+1;
GeneralForm.Category.options[GeneralForm.Category.length-1].text=m_Category;
GeneralForm.Category.options[GeneralForm.Category.length-1].value=m_Category;
GeneralForm.Category.options[GeneralForm.Category.length-1].selected="selected";
}
}
</script>
<input type="button" value="." id="" name="" onclick="AddCategory()">
</td>
<td width="20%" class="TdClassHigh"><input name="Body" size="10" value="">
</td>
<td width="40%" class="TdClassHigh"><input type="file" name="OLEFile" size="10" value=""><a href="#">浏览媒体</a></td>
<td width="10%" class="TdClassHigh"><input type="button" onclick="GeneralSubmit('Add','NULL')" value="增加" id=Add name=Add></td>
</tr>
<%
odbcQuery="select * from GeneralSystem";
odbcRs=odbcStmt.executeQuery(odbcQuery);
String Id,Type;
int iCount;
iCount=0;
while(odbcRs.next())
{
Id=odbcRs.getString("ID");
Type=odbcRs.getString("Type");
strCategory=odbcRs.getString("Category");
if(iCount%2==0)
{
%>
<tr>
<td width="10%" class="TdClassLow"><input name="Subject<%=Id%>" size="10" value="<%=odbcRs.getString("Subject")%>"></td>
<td width="20%" class="TdClassLow">
<select name="Category" size=1 style="width:80%">
<option value="<%=strItemID%>">--请选择--</option>
<%
odbcQuery="select distinct Category from GeneralSystem where ItemID='"+strItemName+"'";
odbcRsExtend=odbcStmtExtend.executeQuery(odbcQuery);
while(odbcRsExtend.next())
{
strCategoryExtend=odbcRsExtend.getString("Category");
%>
<option value="<%=strCategoryExtend%>" <%if(strCategoryExtend.equals(strCategory)){%>selected<%}else{}%>><%=strCategoryExtend%></option>
<%
}
odbcRsExtend.close();
%>
</select>
</td>
<td width="20%" class="TdClassLow"><input name="Body<%=Id%>" size="10" value="<%=odbcRs.getString("Body")%>" ></td>
<td width="40%" class="TdClassLow"><input type="file" name="OLEFile<%=Id%>" size="10" value=""><a href="#" onclick="ShowGeneral('<%=Id%>','<%=Type%>')">浏览媒体</a></td>
<td width="10%" class="TdClassLow"><input type="button" onclick="GeneralSubmit('Modify','<%=Id%>')" value="修改" id=Modify name=Modify><input type="button" onclick="GeneralSubmit('Del','<%=Id%>')" value="删除" id=Del name=Del></td>
</tr>
<% }else{%>
<tr>
<td width="10%" class="TdClassHigh"><input name="Subect<%=Id%>" size="10" value="<%=odbcRs.getString("Subject")%>"></td>
<td width="20%" class="TdClassHigh">
<select name="Category" size=1 style="width:80%">
<option value="<%=strItemID%>">--请选择--</option>
<%
odbcQuery="select distinct Category from GeneralSystem where ItemID='"+strItemName+"'";
odbcRsExtend=odbcStmtExtend.executeQuery(odbcQuery);
while(odbcRsExtend.next())
{
strCategoryExtend=odbcRsExtend.getString("Category");
%>
<option value="<%=strCategoryExtend%>" <%if(strCategoryExtend.equals(strCategory)){%>selected<%}else{}%>><%=strCategoryExtend%></option>
<%
}
odbcRsExtend.close();
%>
</select>
</td>
<td width="20%" class="TdClassHigh"><input name="Body<%=Id%>" size="10" value="<%=odbcRs.getString("Body")%>" ></td>
<td width="40%" class="TdClassHigh"><input type="file" name="OLEFile<%=Id%>" size="10" value=""><a href="#" onclick="ShowGeneral('<%=Id%>','<%=Type%>')">浏览媒体</a></td>
<td width="10%" class="TdClassHigh"><input type="button" onclick="GeneralSubmit('Modify','<%=Id%>')" value="修改" id=Modify name=Modify><input type="button" onclick="GeneralSubmit('Del','<%=Id%>')" value="删除" id=Del name=Del></td>
</tr>
<%
}
iCount++;
}
odbcRs.close();
%>
</table>
<br>
<table border="0" cellpadding="0" cellspacing="0" width="80%">
<tr>
<td width="100%" class="TdClassHead"><input type="button" value="返回" id="Return" name="Return" onclick="window.location.href='/System/Index.jsp'"></td>
</tr>
</table>
</form>
</center>
<%@ include file="/TemplateLib/Tail.jsp"%>
<%@ include file="/DataIni/DataClose.jsp"%>
</body></html>
<%@ page contentType="text/html; charset=gb2312"%>
<%@ include file="/DataIni/DataOpen.jsp"%>
<%@ include file="/ScriptLib/Init.jsp"%>
<%
int iTotalByte,iTotalRead,iReadByte;
iTotalByte=request.getContentLength();
iTotalRead=0;
iReadByte=0;
byte[] Buffer=new byte[iTotalByte];
if(iTotalByte>0)
{
for(;iTotalRead<iTotalByte;iTotalRead+=iReadByte)
{
try
{
iReadByte=request.getInputStream().read(Buffer,iTotalRead,iTotalByte-iTotalRead);
}
catch(Exception e)
{
e.printStackTrace();
}
}
String strContentType=request.getContentType();
//数据处理开始
String strBuffer=new String(Buffer);
%><!--<br>表单数据:<br>strBuffer<br>--><%
String strBoundary="--"+strContentType.substring(strContentType.lastIndexOf("=")+1,strContentType.length());
String strArray[]=strBuffer.split(strBoundary); String strSubString;
int iBegin,iEnd;
iBegin=0;iEnd=0;
String strFieldName="";
String strFieldValue="";
String strFilePath="";
String strFileName="";
String strFileType="";
boolean bTrue;
bTrue=false;
int iLocation=0;
for(int iIndex=1;iIndex<strArray.length-1;iIndex++)
{
strSubString=strArray[iIndex];
iBegin=strSubString.indexOf("name=\"",0);
if(iBegin!=-1)
{
strFieldName="";strFieldValue="";
strFilePath="";strFileName="";strFileType="";
iEnd=strSubString.indexOf("\"",iBegin+6);
strFieldName=strSubString.substring(iBegin+6,iEnd);
iBegin=strSubString.indexOf("filename=\"",0); if(iBegin!=-1)
{
bTrue=true;
}
iEnd=strSubString.indexOf("\r\n\r\n",0);
if(bTrue==true)
{
//文件路径
strFilePath=strSubString.substring(iBegin+10,strSubString.indexOf("\"",iBegin+10));strFileName=strFilePath.substring(strFilePath.lastIndexOf("\\")+1);
strFileType=strSubString.substring(strSubString.indexOf("Content-Type: ")+14,strSubString.indexOf("\r\n\r\n"));
%><!--<br>文件类型:<br>strFileType<br>--><%
//文件数据
iBegin=strSubString.indexOf("\r\n\r\n",iBegin);
strFieldValue=strSubString.substring(iBegin+4);
strFieldValue=strFieldValue.substring(0,strFieldValue.lastIndexOf("\n")-1);
%><!--<br>文件路径:<br>strFilePath<br>文件名称:<br>strFileName<br>--><%
byte[] pFile=strFieldValue.getBytes();
byte[] pFileExtend=new byte[pFile.length];
iLocation=strBuffer.indexOf("filename=\"",iLocation);
for(int kIndex=iLocation;kIndex<iTotalByte-2;kIndex++)
{
if(Buffer[kIndex]==13&&Buffer[kIndex+2]==13)
{iLocation=kIndex+4;break;}
}
for(int nIndex=0;nIndex<pFile.length;nIndex++)
{
pFileExtend[nIndex]=Buffer[iLocation+nIndex];
}
/*
//保存到Local Disk;
FileOutputStream pFileOutputStream=new FileOutputStream("F:\\Site_ColligateStatistic\\UploadFile\\"+strFileName);
pFileOutputStream.write(pFileExtend);
pFileOutputStream.close();
*/
session.putValue(strFieldName+"_FileType",strFileType);
session.putValue(strFieldName+"_FilePath",strFilePath);
session.putValue(strFieldName+"_FileName",strFileName);
session.putValue(strFieldName,pFileExtend);
}
else
{
strFieldValue=strSubString.substring(iEnd+4);
strFieldValue=strFieldValue.substring(0,strFieldValue.lastIndexOf("\n")-1);
session.putValue(strFieldName,strFieldValue);
}
bTrue=false;
}
%><!--<br>表单域名:<br>strFieldName<br>表单域值:<br>strFieldValue<br>--><%
}
//数据处理结束
String TypeValue,Id,ItemID;
TypeValue=(String)session.getValue("TypeValue");
ItemID=(String)session.getValue("ItemId");
%><br><%=TypeValue%><br><%=ItemID%><br><%
if(TypeValue!=null)
{
int iDoAction;
iDoAction=0;
if(TypeValue.indexOf("Add",0)!=-1)
{iDoAction=1;}
if(TypeValue.indexOf("Modify")!=-1)
{iDoAction=2;}
if(TypeValue.indexOf("Del")!=-1)
{iDoAction=3;}
odbcQuery="";
Id=(String)session.getValue("RecordId");
switch(iDoAction)
{
case 1:
odbcStmt.executeUpdate("insert into GeneralSystem(ItemID,Category,Subject,Body,History,Type) values('"+ItemID+"','"+(String)session.getValue("Category")+"','"+(String)session.getValue("Subject")+"','"+(String)session.getValue("Body")+"',Now(),'"+(String)session.getValue("OLEFile_FileType")+"')");
odbcRs=odbcStmtUpdate.executeQuery("select top 1 * from GeneralSystem order by ID desc");
if(odbcRs.next())
{
byte[] OLEFile=(byte[])session.getValue("OLEFile");
odbcRs.updateBinaryStream("OLEFile",new ByteArrayInputStream(OLEFile),OLEFile.length);
odbcRs.updateRow();
odbcRs.close();
response.sendRedirect("/System/GeneralSystem/List.jsp");
}
break;
case 2:
response.sendRedirect("/System/GeneralSystem/List.jsp");
break;
case 3:
odbcStmt.executeUpdate("delete from GeneralSystem where ID="+Id);
response.sendRedirect("/System/GeneralSystem/List.jsp");
break;
}
}
}
%>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title></title>
<link rel="stylesheet" type="text/css" href="/StyleLib/Default_Style_Sheet.css">
</head><body onload="window.alert('动作失败,系统取消操作!');window.location.href='/System/GeneralSystem/List.jsp';">
<%@ include file="/TemplateLib/Head.jsp"%>
<%@ include file="/TemplateLib/Tail.jsp"%>
<%@ include file="/DataIni/DataClose.jsp"%>
</body></html>
<%@ page contentType="text/html; charset=gb2312"%>
<%@ include file="/DataIni/DataOpen.jsp"%>
<%@ include file="/ScriptLib/Init.jsp"%>
<%
String Id;
Id=request.getParameter("Id");
odbcQuery="select * from GeneralSystem where ID="+Id;
odbcRs=odbcStmt.executeQuery(odbcQuery); byte[] Buffer=new byte[1024*10];
InputStream InData=null;
OutputStream outData=null;
int iSize;
if(odbcRs.next())
{
outData=response.getOutputStream();
InData=odbcRs.getBinaryStream("OLEFile");
response.setContentType(odbcRs.getString("Type"));
while(true)
{
iSize=InData.read(Buffer);
if(iSize==-1)
{
break;
}
outData.write(Buffer,0,iSize);
}
outData.flush();
response.flushBuffer();
}
odbcRs.close();
%>
<%@ include file="/DataIni/DataClose.jsp"%>
<html>
<head>
<title>File Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF" text="#000000"><p><font size="5"color="#FF0000">
<b>第七章 檔案上傳範例</b></font></p><form name="Form1" enctype="multipart/form-data" method="post" action="file.jsp">
<p>上傳檔案 1: <input type="file"name="File1" size="20" maxlength="20"> </p>
<p>檔案1敘述: <input type="text" name="File1" size="30" maxlength="50"> </p>
<p>上傳檔案 2: <input type="file" name="File2" size="20" maxlength="20"> </p>
<p>檔案2敘述: <input type="text" name="File2" size="30" maxlength="50"> </p>
<p>上傳檔案3: <input type="file" name="File3" size="20" maxlength="20"> </p>
<p>檔案3敘述: <input type="text" name="File3" size="30" maxlength="50"> </p>
<p> <input type="submit"value="上傳"> <input type="reset" value="清除"> </p>
</form></body>
</html>
file.jsp
<%@ page language="java" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.oreilly.servlet.MultipartRequest" %><%!
// 宣告將上傳之檔案放置到伺服器的C:\Upload目錄中
// 宣告限制上傳之檔案大小為 5 MB
String saveDirectory = "C:\\Upload\\";
int maxPostSize = 5 * 100 * 1024 ; // 宣告敘述上傳檔案內容的變數,型態為String
String FileDescription[] = {null,null,null}; // 宣告上傳檔案名稱 String FileName = null;
// 計算上傳檔案之個數 int count = 0 ;
%><html>
<head>
<title>File Upload</title>
</head><%
// 產一個新的MultipartRequest 的物件,multi
MultipartRequest multi = new MultipartRequest(request,saveDirectory,maxPostSize);
int count =0;
%>
<body>
<%
// 判斷是否有取得檔案敘述,
// 若有,將資料給FileDescription
// 若無,將FileDescription的內容設為空白字串
if ( multi.getParameter("File1") != null )
{
FileDescription[0] = multi.getParameter("File1");
}
else
{
FileDescription[0] = "";
}
if ( multi.getParameter("File2") != null )
{
FileDescription[1] = multi.getParameter("File2");
}
else
{
FileDescription[1] = "";
} if ( multi.getParameter("File3") != null )
{
FileDescription[2] = multi.getParameter("File3");
}
else
{
FileDescription[2] = "";
}
// 取得所有上傳之檔案輸入型態名稱
Enumeration filesname = multi.getFileNames();
while (filesname.hasMoreElements())
{
String name = (String) filesname.nextElement();
String FileName = multi.getFilesystemName(name);
File f = multi.getFile(name);
String ContentType = multi.getContentType(name);
if (FileName != null)
{
count ++;%>
<font color="red">你上傳的第<%=count%>個的檔案:</font><br>
檔案名稱為:<%=FileName%><br>
檔案型態為:<%=ContentType%><br>
檔案的敘述:<%=FileDescription[count-1]%><br><br><%
} // end if
} // end while
%>
您總共上傳<font color="red"><%=count%></font>個檔案
</body>
</html>
<html>
<head>
<title>文件上传</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="40" marginwidth="0" marginheight="0">
<center>
<h1>文件上传</h1>
<form name="uploadform" method="POST" action="save.jsp" ENCTYPE="multipart/form-data">
<table border="1" width="450" cellpadding="4" cellspacing="2" bordercolor="#9BD7FF">
<tr>
<td width="100%" colspan="2">
文件1:<input name="file1" size="40" type="file">
</td>
</tr>
<tr>
<td width="100%" colspan="2">
文件2:<input name="file2" size="40" type="file">
</td>
</tr>
<tr>
<td width="100%" colspan="2">
文件3:<input name="file3" size="40" type="file">
</td>
</tr>
</table>
<br/>
<br/>
<table>
<tr>
<td align="center">
<input name="upload" type="submit" value="开始上传"/>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
/***************************************************/
<%@ page language="java" contentType="text/html;charset=GB2312"%>
<%@ page import="java.util.*"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<%@ page import="java.io.*"%>
<html>
<head>
<title>保存上传文件</title>
</head>
<%
String msg ="";
DiskFileUpload fu= new DiskFileUpload();
// 设置允许用户上传文件大小,单位:字节
fu.setSizeMax(10000000);
// maximum size that will be stored in memory?
// 设置最多只允许在内存中存储的数据,单位:字节
//fu.setSizeThreshold(4096);
fu.setSizeThreshold(4096);
// 设置一旦文件大小超过getSizeThreshold()的值时数据存放在硬盘的目录
fu.setRepositoryPath("C:\\TEMP");
//开始读取上传信息
List fileItems = fu.parseRequest(request);
%>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="40" marginwidth="0" marginheight="0">
<font size="6" color="blue">文件列表:</font>
<center>
<table cellpadding=0 cellspacing=1 border=1 width="100%">
<tr>
<td bgcolor="#008080">文件名</td>
<td bgcolor="#008080">大小</td>
</tr>
<%
// 依次处理每个上传的文件
Iterator iter = fileItems.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
//忽略其他不是文件域的所有表单信息
if (!item.isFormField()) {
String name = item.getName();
long size = item.getSize();
if((name==null||name.equals("")) && size==0)
continue;
%>
<tr>
<td><%=item.getName()%></td>
<td><%=item.getSize()%></td>
</tr>
<%
//保存上传的文件到指定的目录,转换文件名
name = name.replace(':','_');
name = name.replace('\\','_');
File file = new File("E:\\upload\\"+name);
//item.write(new File("E:\\" + name));
item.write(file);
}
}
%>
</table>
<br/><br/>
<a href="upload.jsp">返回上传页面</a>
</center>
</body>
</html>
在STRUTS-EXAMPLES 的目录里面,有一个 struts-upload 的目录。
那里有源代码。自己看下就知道了!
原来是request.getParameter("控件名"),不知道现在是什么啊?????
里面有下载模块,配制采用xml,自己写的上传类,bean也是公开的。
form用了enctype="multipart/form-data" 后,本页面的控件的值,在下个页面怎么取得啊,原来是request.getParameter("控件名"),不知道现在是什么啊?????
还有用了jspsmartupload组件后,我的download是先上传再下载的,在下载时点取消的话,怎么对已经上传了的文件进行删除呢?
希望各位能回答
谢谢大家的踊跃回答!