使用jspSmartUpload组件,除了上传一些文件,还要上传表单的内容

sample.htm

-----------------------------------------------------------------------------------------

<HTML>
<BODY BGCOLOR="white">

<H1>jspSmartUpload : Sample 5</H1>
<HR>

<form METHOD="POST" ACTION="/jspsmartupload/jsp/sample5.jsp" NAME="PW" ENCTYPE="multipart/form-data">
  <table CELLSPACING="0" CELLPADDING="3" BORDER="1" WIDTH="474">

<!-- FILE -->
    <tr>
      <td><small><font face="Verdana">Select&nbsp;a&nbsp;first&nbsp;file&nbsp;:&nbsp; </font></small></td>
      <td><small><font face="Verdana"><input TYPE="file" name="FILE1"></font></small></td>
    </tr>

    <tr>
      <td><small><font face="Verdana">Select&nbsp;a&nbsp;second&nbsp;file&nbsp;:&nbsp; </font></small></td>
      <td><small><font face="Verdana"><input TYPE="file" name="FILE2"></font></small></td>
    </tr>

<!-- TEXT -->
    <tr>
      <td width="150"><div align="left"><p><small><font face="Verdana">Text :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana"><input TYPE="TEXT" name="myText" value=""><br></font></small></td>
    </tr>

<!-- TEXTAREA -->
    <tr>
      <td width="150"><div align="left"><p><small><font face="Verdana">Text Area :&nbsp; </font></small></td>
      <td width="324"><small><font face="Verdana"><textarea name="myTextArea" rows="4" value=""></textarea><br></font></small></td>
    </tr>

<!-- PASSWORD -->
    <tr>
      <td><div align="left"><p><small><font face="Verdana">PassWord :&nbsp; </font></small></td>
      <td><small><font face="Verdana"><input TYPE="PASSWORD" name="myPASSWORD" value=""><br></font></small></td>
    </tr>

<!-- HIDDEN -->
    <tr>
      <td><div align="left"><p><small><font face="Verdana">Hidden :&nbsp; </font></small></td>
      <td><small><font face="Verdana"><input TYPE="hidden" name="myHidden" value="hidden"><br></font></small></td>
    </tr>

<!-- CHECKBOX -->
    <tr>
      <td><div align="left"><p><small><font face="Verdana">CheckBox :&nbsp; </font></small></td>
      <td><small><font face="Verdana"><input TYPE="CHECKBOX" name="myCheckBox" value="Value 1">Value 1<br><input TYPE="CHECKBOX" name="myCheckBox" value="Value 2">Value 2<br><input TYPE="CHECKBOX" name="myCheckBox" value="Value 3">Value 3<br></font></small></td>
    </tr>

<!-- RADIO -->
    <tr>
      <td><div align="left"><p><small><font face="Verdana">Radio :&nbsp; </font></small></td>
      <td><small><font face="Verdana"><input TYPE="radio" name="radio" value="Value 1">Value 1<br><input TYPE="radio" name="radio" value="Value 2">Value 2<br><input TYPE="radio" name="radio" value="Value 3">Value 3<br></font></small></td>
    </tr>

<!-- SELECT -->
    <tr>
      <td><div align="left"><p><small><font face="Verdana">Simple Select :&nbsp; </font></small></td>
      <td><small><font face="Verdana"><SELECT name="mySimpleSelect" ><OPTION value="Value 1">Value 1</OPTION><OPTION value="Value 2">Value 2</OPTION><OPTION value="Value 3">Value 3</OPTION></SELECT><br></font></small></td>
    </tr>

<!-- SELECT MULTIPLE  -->
    <tr>
      <td><div align="left"><p><small><font face="Verdana">Multiple Select :&nbsp; </font></small></td>
      <td><small><font face="Verdana"><SELECT multiple name="myMultSelect" ><OPTION value="Value 1">Value 1</OPTION><OPTION value="Value 2">Value 2</OPTION><OPTION value="Value 3">Value 3</OPTION></SELECT><br></font></small></td>
    </tr>

<!-- SUBMIT -->
    <tr>
      <td colspan="2" width="474"><div align="center"><center><p><small><font face="Verdana"><input
      TYPE="Submit"> </font></small></td>
    </tr>
  </table>
</form>

</BODY>
</HTML>

sample.jsp

---------------------------------------------------------------------------------------------------------------------------

<%@ page language="java" import="com.jspsmart.upload.*"%>
<jsp:useBean id="myUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />

<HTML>
<BODY BGCOLOR="white">

<H1>jspSmartUpload : Sample 5</H1>
<HR>

<%

 // Initialization
 myUpload.initialize(pageContext);

 // Upload
 myUpload.upload();  

 //
 // Files
 //

 out.println("<BR><STRONG>Display information about Files</STRONG><BR>");

 out.println("Number of files = " + myUpload.getFiles().getCount() + "<BR>");
 //out.println("Total size (bytes) = " + myUpload.getFiles().getSize() +"<BR>");

 for (int i=0;i<myUpload.getFiles().getCount();i++){
  
  out.print(myUpload.getFiles().getFile(i).getFieldName());
  if (!myUpload.getFiles().getFile(i).isMissing())
   out.print(" = " + myUpload.getFiles().getFile(i).getFileName() + " (" + myUpload.getFiles().getFile(i).getSize() + ")");
  else
   out.print(" = vide");  
  out.println("<BR>");
 }


 //
 // Request
 //

 out.println("<BR><BR><STRONG>Display information about Requests</STRONG><BR>");


 // Retreive Requests' names
 java.util.Enumeration e = myUpload.getRequest().getParameterNames();

 // Retreive parameters
 while (e.hasMoreElements()) {

  String key = (String)e.nextElement();
  String[] values = myUpload.getRequest().getParameterValues(key);   
  
  // Browse the current parameter values
  for(int i = 0; i < values.length; i++) {
     out.print(key + " = ");
     out.print(values[i] + "<BR>");
  }  
 }

%>


</BODY>
</HTML>

在我的应用中需要使用相应的逻辑如下:

test.jsp----------------------------------------------------------------------------------------

<%@ page language="java" import="java.util.*,com.jspsmart.upload.*,java.sql.*"%>
<jsp:useBean id="myUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<HTML>
<BODY BGCOLOR="white">
<H1>jspSmartUpload : Sample 5</H1>
<HR>
<%
 myUpload.initialize(pageContext);
 myUpload.upload();  

 out.println("<BR><BR><STRONG>Display information about Requests</STRONG><BR>");


 // Retreive Requests' names
 java.util.Enumeration e = myUpload.getRequest().getParameterNames();
 String[] values=null;
 
 values = myUpload.getRequest().getParameterValues("product_name");
 String product_name = values[0];
 //out.print(product_name);
 if(product_name==null){
  product_name="";
 }
 
 values = myUpload.getRequest().getParameterValues("producer");
 String producer = values[0];
 out.print(producer);
 if(producer==null){
  producer="";
 } 
 
 values = myUpload.getRequest().getParameterValues("type");
 String type = values[0];
 out.print(type);
 if(type==null){
  type="";
 }
 
 values = myUpload.getRequest().getParameterValues("Number");
 String Number = values[0];
 out.print(Number);
 if(Number==null){
  Number="";
 } 
 
 values = myUpload.getRequest().getParameterValues("price");
 String price = values[0];
 out.print(price);
 if(price==null){
  price="";
 }
 
 values = myUpload.getRequest().getParameterValues("buying_date");
 String buying_date = values[0];
 out.print(buying_date);
 if(buying_date==null){
  buying_date="";
 }
 
 values = myUpload.getRequest().getParameterValues("gdzc_id");
 String gdzc_id = values[0];
 out.print(gdzc_id);
 if(gdzc_id==null){
  gdzc_id="";
 }
 
 values = myUpload.getRequest().getParameterValues("product_id");
 String product_id = values[0];
 out.print(product_id);
 if(product_id==null){
  product_id="";
 }
 
 
 
 String url = "jdbc:odbc:test";
 Connection con;
 Statement stmt;

 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
 String Insert= "insert into product(product_name,producer,type,count,price,buying_date,product_id,gdzc_id) values('"+product_name+"','"+producer+"','"+type+"','"+Number+"','"+price+"','"+buying_date+"','"+product_id+"','"+gdzc_id+"');";
 String InsertStr = new String(Insert.getBytes("ISO8859_1"),"gb2312");
 out.println("<br>"+InsertStr);
 con = DriverManager.getConnection(url, "admin", "");
 stmt = con.createStatement();
 stmt.executeUpdate(InsertStr);

 String id = "";
 String query = "select max(id) from Product";
 ResultSet rs = stmt.executeQuery(query);
 while(rs.next()){
  id = rs.getString(1);
 }
 
 out.println("1---id-------------------------"+id);


 
 //
 // Files
 //

 out.println("<BR><STRONG>Display information about Files</STRONG><BR>");

 out.println("Number of files = " + myUpload.getFiles().getCount() + "<BR>");
 //out.println("Total size (bytes) = " + myUpload.getFiles().getSize() +"<BR>");
 
 com.jspsmart.upload.File image = myUpload.getFiles().getFile(0);
 if (!image.isMissing()){
  image.saveAs("/test/upload/" + id + "." +image.getFileExt(),myUpload.SAVE_VIRTUAL);
 }
 
 com.jspsmart.upload.File fapiao = myUpload.getFiles().getFile(1);
 if (!fapiao.isMissing()){
  image.saveAs("/test/upload/" + id + "_fapiao." +image.getFileExt(),myUpload.SAVE_VIRTUAL);
 }
 for (int i=0;i<myUpload.getFiles().getCount();i++){
  out.print(myUpload.getFiles().getFile(i).getFieldName());
  if (!myUpload.getFiles().getFile(i).isMissing())
   out.print(" = " + myUpload.getFiles().getFile(i).getFileName() + " (" + myUpload.getFiles().getFile(i).getSize() + ")");
  else
   out.print(" = vide");  
  out.println("<BR>");
 }
 
 
 stmt.close();
 con.close();
 response.sendRedirect("./search.jsp");
%>
</BODY>
</HTML>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值