• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

handling html parameters in a jsp page

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi to all!
I have the following code in a jsp page:

<% for (int i = 0; i < collectionArray.length; i++) {
%>
<tr>
<td width="18%"><a href="documentview.jsp?id=<%= collectionArray[i]%>"><%= collectionArray[i] %></a></td>
<td width="17%"><input type="checkbox" name="checkbox" value="<%= collectionArray[i] %>" >
</td>
</tr>
<%
}
}
catch (XMLDBException e) {
response.getWriter().println("adminstart.jsp Exception occured " + e.errorCode);
}
finally {
if (col != null) {
col.close();
}
}%>
</table>

<p>
<input type="submit" name="choice" value="Delete Checked Collection" >

</form>
<p>
<form name="insertionForm" action="CollectionFormProcess" method=post >
<input type="submit" name="choice" value="Insert a collection name" >
<input type="text" name="collectionName" >
</form>
</p>
iwould like to know if it is possible to get the value of the submit html variable...
i would like to know if it possible to write the following:
<% if choice.value.equals(null) choice.value= "Insert a collection name" %>
my problem is that the servlet rises a NullPointerException when an user write some text in the collectionName field and press Enter because the servlet makes an if-clause on the "choice" value
if (request.getParameter("choice").equals("Insert a collection name")) {
//some code
}
else
// other code

any help would be highly appreciated
thank you in advance
federico
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
From what I see in the code you posted, when you call
request.getParameter("choice")
it should return the string "Insert a collection name", I tried it and it works.
are you sure the exception is comming from that statement?
Dominic
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are calling equals on null. Try this...
<% if choice.value == null) choice.value= "Insert a collection name" %>
 
Dominic Paquette
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think that calling equals with a null parameter throws an exception, I think it simply returns false
Dominic
 
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dominic is right. it just returns false.
to the main questio: can you please post your code as it is in your java/jsp file?
 
reply
    Bookmark Topic Watch Topic
  • New Topic