Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Receives null value

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai all,
while i try to upload image file to server i dont get the getParameter values of name1 and image1. Could any one tell me where can be my mistake. Upload of the image works fine.
regards
prabhakar.
My Servlet Prog
~~~~~~~~~~~~~~~
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;
import com.oreilly.servlet.*;
public class SaveImageFile extends HttpServlet
{
public void init(ServletConfig config) throws ServletException{
super.init(config);
}
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
PrintWriter out=res.getWriter();
res.setContentType("text/html");
System.out.println("Name Received is:"+req.getParamete("name1"));
out.println("<html><body>");

try{
MultipartRequest m1=new MultipartRequest(req,"c:\\image");
String e1=m1.getParameter("image1");
System.out.println(" File Name :\t "+e1);
System.out.println("ContentType:\t"+m1.getContentType("image1"));
out.println("Execution successfull");
}
catch(Exception e){
out.println("<html><body>");
System.out.println(" Error :\t"+e);
out.println("Error during Processing");
out.println("</body></html>");
out.close();
}

out.println("</body></html>");
out.close();
}
}// End of SaveImageFile
My html file.
~~~~~~~~~~~~~
<html><head><title> Sample testing</title></head>
<BODY BGCOLOR="#ccffcc">
<form ENCTYPE="multipart/form-data" action="http://202.141.81.233:8080/servlet/SaveImageFile"; method="post">
<table>
<tr>
<td> Enter the name :
<input type="text" name="name1" size=10 ></td>
</tr>
<tr>
<td> Choose the image file
<input type="file" name="image1"></td>
</tr>
<tr>
<td><input type="submit" value="submit"></td>
</tr>
</table>
</form>
</head>
</title>
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not be using the req object until after you have sent it to the MultipartRequest constructor.

So ... do not retrieve "name1" until after you send it to the constructor. Also, you can retrieve it from your m1 object.
 
varkala prabhakar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear mike,
my problem is solved for only one request. I get array index out of bounds for nam array. is the code written for retriving for image name is wrong?.
____________________________________________________________
try{
MultipartRequest m1=new MultipartRequest(req,"c:\\image");

System.out.println(" Content Type:\t"+m1.getContentType("image1"));

String []enu= m1.getParameterValues("name1");
String []nam = m1.getParameterValues("image1");

System.out.println("First eke :"+enu[0]);
System.out.println("File Name :"+nam[0]);
out.println("Execution successfull");
}
_____________________________________________________________

thanx
prabhakar.
 
Be reasonable. You can't destroy everything. Where would you sit? How would you read a tiny ad?
ScroogeXHTML 8.7 - RTF to HTML5 and XHTML converter
https://coderanch.com/t/730700/ScroogeXHTML-RTF-HTML-XHTML-converter
    Bookmark Topic Watch Topic
  • New Topic