怎样得到:ENCTYPE="multipart/form-data"中提交的表单的值?

fzlhx 2003-10-27 01:28:55
1.jsp
<FORM METHOD="POST" ACTION="upfile.jsp" ENCTYPE="multipart/form-data">
  文件ID:<input name="id" size="10">
<br/>
<input type="text" name="xgsj">时间

选择要上传文件:<input type="file" name="image">
<br/>
<input type="submit" value="上传" name="submit" size="25">
<input type="reset" value="清除" name="clear" size="25">
<br/> </form>
2.jsp
<%@ page language="java" import="com.jspsmart.upload.*"%>
<%@ page import="java.sql.*"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<jsp:useBean id="conn" scope="page" class="htjs.database.DB_link"/>
<jsp:useBean id="jsp" scope="page" class="htjs.basic.OutString"></jsp:useBean>

<HTML>
<BODY BGCOLOR="white">

<center><H1>上传文件</H1></center>
<HR>
<%
// Variables
int count=0;
String sql="";
//String id=request.getParameter("id1");
String xgsj=request.getParameter("xgsj");
String yhbm=(String)session.getAttribute("yhbm");
String username=(String) session.getValue("username");
// Initialization
mySmartUpload.initialize(pageContext);
// Upload
mySmartUpload.upload();
// Select each file
for (int i=0;i<mySmartUpload.getFiles().getCount();i++){
// Retreive the current file
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
// Save it only if this file exists
if (!myFile.isMissing()) {
// Save the files with its original names in a virtual path of the web server
myFile.saveAs("/upfile/" + myFile.getFileName());
// myFile.saveAs("/upload/" + myFile.getFileName(), mySmartUpload.SAVE_VIRTUAL);
// sample with a physical path
//myFile.saveAs("c:\\temp\\" + myFile.getFileName(),mySmartUpload.SAVE_PHYSICAL);

// Display the properties of the current file
out.println("FieldName = " + myFile.getFieldName() + "<BR>");
out.println("Size = " + myFile.getSize() + "<BR>");
out.println("FileName = " + myFile.getFileName() + "<BR>");
out.println("FileExt = " + myFile.getFileExt() + "<BR>");
out.println("FilePathName = " + myFile.getFilePathName() + "<BR>");
out.println("ContentType = " + myFile.getContentType() + "<BR>");
out.println("ContentDisp = " + myFile.getContentDisp() + "<BR>");
out.println("TypeMIME = " + myFile.getTypeMIME() + "<BR>");
out.println("SubTypeMIME = " + myFile.getSubTypeMIME() + "<BR>");
count ++;
sql="begin insert into tfiles(id,FieldName,Size1,FileName,FileExt,FilePathName,ContentType,ContentDisp,TypeMIME,SubTypeMIME) values('"+yhbm+"','" + myFile.getFieldName() + "','" + myFile.getSize() + "','" + myFile.getFileName() + "','" + myFile.getFileExt() + "','" + myFile.getFilePathName() + "','" + myFile.getContentType() + "','" + myFile.getContentDisp() + "','" + myFile.getTypeMIME() + "','" + myFile.getSubTypeMIME()+ "');end;";
conn.executeQuery(sql);
out.print(sql);


}

}

// Display the number of files which could be uploaded
out.println("<BR>" + mySmartUpload.getFiles().getCount() + " files could be uploaded.<BR>");

// Display the number of files uploaded
out.println(count + "个文件上传成功.");

if (conn!=null) conn.close();
%>
</BODY>
</HTML>
问题:怎样得到1.jsp中的xgsj(时间的值)?
我用的上传组件:jspsmart.
...全文
147 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
superszhu 2003-10-28
  • 打赏
  • 举报
回复
JSP环境中用
mySmartUpload.initialize(pageContext);

servlet中用
SmartUpload.initialize(config,request,response);
fzlhx 2003-10-27
  • 打赏
  • 举报
回复
SmartUpload.initialize(config,request,response); 中的config,request,response
private ServletConfig config;
private ServletResponse response;
PageContext pageContext;
ServletRequest request;
这样定义对话为什么不对啊?
fzlhx 2003-10-27
  • 打赏
  • 举报
回复
SmartUpload.initialize(config,request,response); 中的config,request,response
private ServletConfig config;
private ServletResponse response;
PageContext pageContext;
ServletRequest request;
这样定义对话.
superszhu 2003-10-27
  • 打赏
  • 举报
回复
// Initialization
mySmartUpload.initialize(pageContext);

// Upload
mySmartUpload.upload();

String path = mySmartUpload.getRequest().getParameter("PATH")
superszhu 2003-10-27
  • 打赏
  • 举报
回复
希望你能看明白::)

m_requtest: HttpServletRequest
m_formRequest:


int m_totalBytes = m_request.getContentLength();
Byte[] m_binArray = new byte[m_totalBytes];
int j;
for(; i < m_totalBytes; i += j)
try
{
m_request.getInputStream();
j = m_request.getInputStream().read(m_binArray, i, m_totalBytes - i);
}
catch(Exception exception)
{
}

for(; !flag1 && m_currentIndex < m_totalBytes; m_currentIndex++)
if(m_binArray[m_currentIndex] == 13)
flag1 = true;
else
m_boundary = m_boundary + (char)m_binArray[m_currentIndex];

if(m_currentIndex == 1)
return;
for(m_currentIndex++; m_currentIndex < m_totalBytes; m_currentIndex = m_currentIndex + 2)
{
String s1 = getDataHeader();
m_currentIndex = m_currentIndex + 2;
boolean flag3 = s1.indexOf("filename") > 0;
String s3 = getDataFieldValue(s1, "name");
getDataSection();
String s11 = new String(m_binArray, m_startData, (m_endData - m_startData) + 1);
putParameter(s3, s11);
if((char)m_binArray[m_currentIndex + 1] == '-')
break;
}



private void getDataSection()
{
boolean flag = false;
String s = new String();
int i = m_currentIndex;
int j = 0;
int k = m_boundary.length();
m_startData = m_currentIndex;
m_endData = 0;
while(i < m_totalBytes)
if(m_binArray[i] == (byte)m_boundary.charAt(j))
{
if(j == k - 1)
{
m_endData = ((i - k) + 1) - 3;
break;
}
i++;
j++;
} else
{
i++;
j = 0;
}
m_currentIndex = m_endData + k + 3;
}


protected void putParameter(String s, String s1)
{
Hashtable m_parameters = new Hashtable();
int m_counter = 0;
if(s == null)
throw new IllegalArgumentException("The name of an element cannot be null.");
if(m_parameters.containsKey(s))
{
Hashtable hashtable = (Hashtable)m_parameters.get(s);
hashtable.put(new Integer(hashtable.size()), s1);
} else
{
Hashtable hashtable1 = new Hashtable();
hashtable1.put(new Integer(0), s1);
m_parameters.put(s, hashtable1);
m_counter++;
}
}
fuzhan820 2003-10-27
  • 打赏
  • 举报
回复
mySmartUpload.initialize(pageContext);与mySmartUpload.initialize(config,request,response);关系?
samwong 2003-10-27
  • 打赏
  • 举报
回复
private ServletConfig config;
private String[] fileName;

final public void init(ServletConfig config) throws ServletException {
this.config = config;
}
final public ServletConfig getServletConfig() {
return config;
}
SmartUpload mySmartUpload=new SmartUpload();
// Initialization
mySmartUpload.initialize(config,request,response);
String operation=mySmartUpload.getRequest().getParameter("operation").trim();
fzlhx 2003-10-27
  • 打赏
  • 举报
回复
String xgsj=request.getParameter("xgsj");得不到值为什么?

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧