用于fileupload的BackGround图像 [英] BackGround image for fileupload

查看:66
本文介绍了用于fileupload的BackGround图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家

i希望代码为文件上传选项设置图像..我可以点击该图片打开浏览器选项..我怎么能这样做..







please helpme ..








谢谢和问候

Ch.Nagendra

解决方案

< blockquote>试试这个代码...... :)

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

index.jsp

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

 <  < span class =code-leadattribute> html  >  
< head >
< title > 向用户显示文件上传表单< / title >
< / head >
< body >
< 表格 enctype = multipart / form-data action = upload.jsp 方法 = POST >
< br >
< br >
< br >
< center >
< border = 0 bgcolor = #ccFDDEE >
< tr >
< center >
< td colspan = 2 align = center > < b > 上传文件< / b >
< center >
< < span class =code-leadattribute> / center > < / td >
< < span class =code-leadattribute> / center > < / tr >
< < span class =code-leadattribute> tr >
< td colspan = 2 align = center > < / td >
< / tr >
< tr >
< td > < b > 选择要上传的文件:< / b > < / td >
< td > < 输入 名称 = file type = file > < / input > < / td >
< / tr >
< tr >
< td colspan = 2 align = center > < / td >
< / tr >
< tr >
< td colspan = 2 align = center > ; < 输入 类型 = 提交 >
value =发送文件> < / input > < / td >
< / tr >
< 表格 >
< / table > < / table > < / center >
< / br > < / br > < / br > < / form >
< / body >
< / html >











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



upload.jsp

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





 <  ![CDATA [<%@     page     import   =  java.io。*  > ]]> 
< ![CDATA [<%

字符串 saveFile = ;

字符串 contentType = request.getContentType();

如果 ( (contentType = null) && (contentType.indexOf(multipart / form-data) > ; = 0)){
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
byte dataBytes [] = new byte [formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while(totalBytesRead < formDataLength) {

byteRead = in.read(dataBytes, totalBytesRead, formDataLength);

< span class =code-attribute> totalBytesRead + = byteRead;

}

字符串 file = new String(dataBytes);

saveFile = file.substring(file.indexOf( filename = \ + 10);

saveFile = saveFile.substring(0, saveFile.indexOf(\ n));

< span class =code-attribute> saveFile = < span class =code-keyword> saveFile.substring(saveFile.lastIndexOf( \\) + 1, saveFile.indexOf (\));

< span class =code-attribute> int lastIndex = contentType.lastIndexOf( = );
String boundary = contentType.substring(lastIndex + 1,contentType.length());
int pos;
pos = file.indexOf(
filename = \ );

< span class =code-attribute> pos = file.indexOf( \ n, pos) + 1;

pos = file.indexOf( \ n, pos) + 1;

pos = file.indexOf( \ n, pos) + 1;

int boundaryLocation = file.indexOf(boundary, pos) - 4;

< span class =code-attribute> int startPos = ((file.substring(0, pos))。getBytes())。length;

< span class =code-attribute> int endPos = ((file.substring( 0, boundaryLocation))。getBytes())。length;
< span class =code-attribute>
saveFile = C:/ himanshu / + saveFile;

文件 ff = new 文件(saveFile);

< span class =code-attribute>
FileOutputStream fileOut = < span class =code-keyword> new FileOutputStream(ff);

fileOut.write (dataBytes, startPos, (endPos - startPos));

< span class =code-attribute> fileOut.flush();

fileOut.close();

%>]]><br>
<table border=\"2\">
<tr>
<td><b>You have successfully upload the file by the name of:</b>
<%
out.println(saveFile);
}
%>
</td>
</tr>
</table>



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


Hi experts
i want code for to set an image for file-upload option.. i can click that image it opens browser option.. how can i do that..



please helpme..




Thanks and Regards
Ch.Nagendra

解决方案

Try this code... :)
------------------------------------------------------------------------------------------
index.jsp
------------------------------------------------------------------------------------------

<html>
<head>
<title>Display file upload form to the user</title>
</head>
<body>
<form enctype="multipart/form-data" action="upload.jsp" method="POST">
<br>
<br>
<br>
<center>
<table border="0" bgcolor="#ccFDDEE">
      <tr>
            <center>
            <td colspan="2" align="center"><b>UPLOAD THE FILE</b>
            <center>
            </center></td>
      </center></tr>
      <tr>
            <td colspan="2" align="center"></td>
      </tr>
      <tr>
            <td><b>Choose the file To Upload:</b></td>
            <td><input name="file" type="file"></input></td>
      </tr>
      <tr>
            <td colspan="2" align="center"></td>
      </tr>
      <tr>
            <td colspan="2" align="center"><input type="submit">
                  value="Send File"></input></td>
      </tr>
      <table>
            </table></table></center>
            </br></br></br></form>
</body>
</html>






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

upload.jsp
-----------------------------------------------------------------------------------------


<![CDATA[<%@ page import="java.io.*"%>]]>
<![CDATA[<%

      String saveFile = "";

      String contentType = request.getContentType();

      if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
            DataInputStream in = new DataInputStream(request.getInputStream());
            int formDataLength = request.getContentLength();
            byte dataBytes[] = new byte[formDataLength];
            int byteRead = 0;
            int totalBytesRead = 0;
            while (totalBytesRead < formDataLength) {

                  byteRead = in.read(dataBytes, totalBytesRead, formDataLength);

                  totalBytesRead += byteRead;

            }

            String file = new String(dataBytes);

            saveFile = file.substring(file.indexOf("filename=\"") + 10);

            saveFile = saveFile.substring(0, saveFile.indexOf("\n"));

            saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1, saveFile.indexOf("\""));

            int lastIndex = contentType.lastIndexOf("=");
            String boundary = contentType.substring(lastIndex + 1, contentType.length());
            int pos;
            pos = file.indexOf("filename=\"");

            pos = file.indexOf("\n", pos) + 1;

            pos = file.indexOf("\n", pos) + 1;

            pos = file.indexOf("\n", pos) + 1;

            int boundaryLocation = file.indexOf(boundary, pos) - 4;

            int startPos = ((file.substring(0, pos)).getBytes()).length;

            int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;

            saveFile = "C:/himanshu/" + saveFile;

            File ff = new File(saveFile);

            FileOutputStream fileOut = new FileOutputStream(ff);

            fileOut.write(dataBytes, startPos, (endPos - startPos));

            fileOut.flush();

            fileOut.close();

%>]]><br>
<table border="2">
      <tr>
            <td><b>You have successfully upload the file by the name of:</b>
            <%
                  out.println(saveFile);
                  }
            %>
            </td>
      </tr>
</table>


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


这篇关于用于fileupload的BackGround图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆