Bonjour
j'utilise un upload pour envoyer une photo ds un dossier mais celui est en "dur" ds un bean avec useBean et setBean, quelle methode puis je utiliser pour que l'utilisateur puisse choisir lui meme ou il veut stocker ses fichiers
<code>
<html>
<!--<%@ page language="java" import="java.io.*,javax.servlet.*,javax.servlet.http.*" %>-->
<%@ page language="java" import="javazoom.upload.*,java.util.*,javax.swing.JOptionPane" %>
<%@ page errorPage="ExceptionHandler.jsp" %>
<jsp:useBean id="upBean" scope="page" class="javazoom.upload.UploadBean" >
<jsp:setProperty name="upBean" property="folderstore" value="DMeta4/M4WS/fotos" />
</jsp:useBean>
<head>
<title>Samples : Simple Upload</title>
<style TYPE="text/css">
<!--
.style1 {
font-size: 12px;
font-family: Verdana;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<ul class="style1">
<%
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return !name.startsWith("." );
}
};
if (MultipartFormDataRequest.isMultipartFormData(request))
{
// Uses MultipartFormDataRequest to parse the HTTP request.
MultipartFormDataRequest mrequest = new MultipartFormDataRequest(request);
//out.println(request);
String todo = null;
String temp = null;
String afterdot = null;
if (mrequest != null) todo = mrequest.getParameter("todo" );
if ( (todo != null) && (todo.equalsIgnoreCase("upload" )) )
{
Hashtable files = mrequest.getFiles();
if ( (files != null) && (!files.isEmpty()) )
{
//addUploadListener(UploadListener listener);
UploadFile file = (UploadFile) files.get("uploadfile" );
if (file != null)
{
temp = file.getFileName();
int pos = temp.indexOf("." );
// verify there is a dot
if (pos != -1){}
// length of the file name to verify if after the dot there is only gif jpeg jpg
int len = temp.length();
afterdot = temp.substring(pos+1,len);
out.println(afterdot);
if (afterdot.equals("gif" ) || afterdot.equals("jpeg" )|| afterdot.equals("jpg" ))
{
out.println("<li>Form field : uploadfile"+"<BR> Uploaded file : "+file.getFileName()+"("+file.getFileSize()+" bytes)"+"<BR> Content Type : "+file.getContentType());
upBean.store(mrequest, "uploadfile" );
}
else
{
out.println("<BR> Select a file ending by jpeg jpg or gif </BR>" );
//JOptionPane dia = new JOptionPane();
//JOptionPane.showMessageDialog(null, "alert", "alert", JOptionPane.ERROR_MESSAGE);
}
// Uses the bean now to store specified by jsp:setProperty at the top.
}
}
else
{
System.out.println("<li>No uploaded files" );
}
}
else out.println("<BR> todo="+todo);
}
%>
</ul>
<form method="post" action="SimpleUpload.jsp" name="upform" enctype="multipart/form-data">
<table width="60%" border="0" cellspacing="1" cellpadding="1" align="center" class="style1">
<tr>
<td align="left"><b>Select a file to upload :</b></td>
</tr>
<tr>
<td align="left">
<input type="file" name="uploadfile" size="30">
</td>
</tr>
<tr>
<td align="left">
<input type="hidden" name="todo" value="upload">
<input type="submit" name="Submit" value="Upload">
<input type="reset" name="Reset" value="Cancel">
</td>
</tr>
</table>
<br>
<br>
<table border="0" cellspacing="1" cellpadding="0" align="center">
<tr>
<td bgcolor="#666666">
<table width="100%" border="0" cellspacing="1" cellpadding="0" align="center" class="style1">
<tr>
<td bgcolor="#FFFFFF"><b><font color="#0000FF">
HTML tags used in this form : </font></b></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> <<b>form</b>
<b>method</b>="<b><font color="#FF0000">post</font></b>"
<b>action</b>="<b><font color="#FF0000">SimpleUpload.jsp</font></b>"
name="upload" <b>enctype</b>="<b><font color="#FF0000">multipart/form-data</font></b>"></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> <<b>input</b>
<b>type</b>="<b><font color="#FF0000">file</font></b>"
<b>name</b>="<font color="#FF0000"><b>uploadfile</b></font>"
size="50"></td>
</tr>
</table>
</td>
</tr>
</table>
<p> </p>
<p> </p>
<p align="center"> </p>
<p align="center"> </p>
<p align="center"><font size="-1" face="Courier New, Courier, mono">Copyright
© <a href="http://www.javazoom.net" target="_blank">JavaZOOM</a> 1999-2005</font></p>
</form>
</body>
</html>
</code>