Sto cercando di creare una servlet che carichi le immagini in una jsp.
Vi metto il codice che almeno mi spiego meglio:
JSP:
...
<%List<Contatto> contatti = (List<Contatto>)request.getAttribute("listaContatt i");%>
<% for (Contatto c : contatti ) { %>
...
<input type="image" name="foto" src="img/<%=c.getFoto()%>" value="<%=c.getFoto()%>" >
...
WEB.XML
...
<servlet>
<description/>
<display-name>Download</display-name>
<servlet-name>Download</servlet-name>
<servlet-class>download.Download</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Download</servlet-name>
<url-pattern>/img/*</url-pattern>
</servlet-mapping>
...
<context-param>
<param-name>img</param-name>
<param-value>C:\Documents and Settings\mosc\contatti\web\img\</param-value>
</context-param>
...
ed infine la servlet Download:
...
String fileName = (String)request.getParameter("foto");
String path = (String)request.getSession().getServletContext().g etAttribute("img");
BufferedInputStream in = new BufferedInputStream(new FileInputStream(new File(path,fileName)));
byte[] buff = new byte[1024];
int readed = -1;
while((readed = in.read(buff)) != -1){
OutputStream output = response.getOutputStream();
output.write(buff, 0, readed);
...
il problema è che il parametro foto è sempre null....PERCHE'?