Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting null parameters in post

 
khushi paul
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i have written a HTML forms body in doGet method of a servlet and trying to retriev form element values in doPost method of the same servlet.my problem is that some times i get the values by using request.getParameter but many times it just returns null although value has been entered in the form elements.
can anybody pls tell me its reason and possible solution?
regards
khushi
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kindly post your code
 
khushi paul
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here's the code

public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
out.println("<form name=esubmit ENCTYPE='multipart/form-data' method=Post>");

some queries...............

out.println("<p> Div Initials: <INPUT TYPE=\"text\" NAME=\"dinitl\" value='"+rs.getString("r_divn_abrv")+"'> Sec Initials: <INPUT TYPE=\"text\" NAME=\"sinitl\" value="+rs.getString("r_secn_abrv")+"> Indentors Initials: <INPUT TYPE=\"text\" SIZE=\"5\" maxlength=\"5\" NAME=\"iinitl\" > Year: <INPUT TYPE=\"text\" SIZE=\"5\" maxlength=\"5\" NAME=\"year\" value="+pyear+"> Indent SrNo: <INPUT TYPE=\"text\" SIZE=\"5\" maxlength=\"5\" NAME=\"srno\"> <INPUT TYPE='file' NAME='document'> </p> ");
out.println("<INPUT TYPE='submit' VALUE='Save'>");

public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML><body>");
out.println("init="+req.getParameter("iinitl"));

DiskFileUpload upload = new DiskFileUpload();
try{

//Parse the request
List items = upload.parseRequest(req);

// Process the uploaded items
Iterator iter = items.iterator();

while (iter.hasNext()) {
item = (FileItem) iter.next();
if (item.isFormField()) {
String fld=item.getFieldName();
String value=item.getString();
if(fld.equals("dinitl"))
{di=value;}
if(fld.equals("sinitl"))
{si=value;}
if(fld.equals("iinitl"))
{ii=value;}
}
}
out.println(ii);
....

do you need any more explanation?
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ENCTYPE='multipart/form-data'

I dought if you can use HttpRequest object with multipart..try MultiPartRequest
-Praful
[ March 14, 2005: Message edited by: Praful Thakare ]
 
khushi paul
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks,but can u pls give me some code so that i can understand it properly?
and why is it so that my code works some times?
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what tool are you using for upload ?
not sure if following classes are with you,chk out the respective calles in your tool for upload

if (MultipartFormDataRequest.isMultipartFormData(request))
{

// Uses MultipartFormDataRequest to parse the HTTP request.
MultipartFormDataRequest mrequest = new MultipartFormDataRequest(request);
 
khushi paul
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i m using jakarta apache commons fileupload for uploading..
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll need to read the API for fileupload.
'getParameter' doesn't work with multipar forms.

This should give you the basic idea.

[ March 14, 2005: Message edited by: Ben Souther ]
 
khushi paul
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for ur reply ben,
but as u can see in the code that i've posted,i am using
String field=item.getFieldName();
String value=item.getString();

to get name of field and its value,these functions are from fileupload class only.
i am facing a very strange problem...sometimes i get values and at other time i get null.i am neither able to find out the reason nor solve the problem.

however the file uploading part gets implemented succesfully in any case.
pls help me out,its pretty urgent.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
khushi,
I did miss that in your code, sorry.

I've never seen this problem.
If you have a access to a packet sniffer like tcpflow or Ethereal, it might help to look at what, exactly, is being sent up from the browser.

BTW: If you wrap your code in code tags (there is a code button on the page) your indenting will be preserved, making your code much easier to read. This usually means more people will read it and try to help.
 
khushi paul
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll surely take care of that from next time Ben
BTW my problem got solved i donno how
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic