• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

java.util.Enumeration

 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have ShowMessage.html and ShowMessageServlet.java . All work fine.
<HTML>
<HEAD>
<TITLE>XYZ Corporation, Service IT </title>
</HEAD>
<BODY bgcolor="#FCF054">
<H1>Requête </H1>
<HR><BR>

<FORM ACTION="/projet/servlet/ShowMessageServlet" METHOD="POST">
<TABLE CELLSPACING="2" CELLPADDING="2">
<TR>
<TD >Firstname :</TD>
<TD><INPUT TYPE="Text" NAME="firstName" SIZE="20"></TD>
</TR>
<TR>
<TD>Lastname:</TD>
<TD><INPUT TYPE="Text" NAME="lastName" SIZE="20"></TD>
</TR>
<TR>
<TD>email:</TD>
<TD><INPUT TYPE="Text" NAME="email" SIZE="20"></TD>
</TR>
<TR>
<TD>phone :</TD>
<TD><INPUT TYPE="Text" NAME="phone" SIZE="20"></TD>
</TR>
</TABLE>
<BR>
<HR><BR>
<INPUT TYPE="Submit" VALUE="Submit Request">
</FORM>
</BODY>
</HTML>

My Servlet :
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
// Importation des autres paquetages Java
import java.io.*;
public class ShowMessageServlet extends HttpServlet {

protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

String NoValue="NoValue entered";

PrintWriter out = res.getWriter();
res.setContentType("text/html");
out.println("<HTML><HEAD><TITLE>");
out.println(" Confirmation de requête ");
out.println("</TITLE></HEAD>");
out.println("<BODY>");
out.println("<P><U><H3><B>Here are your information :</B></H3></U></P>");
Enumeration enum = req.getParameterNames();
while(enum.hasMoreElements()) {
String paramName=(String)enum.nextElement();
out.println("<TABLE>");
out.println("<TR><TD><B>"+paramName+":</B></TD>");
String paramValue =req.getParameter(paramName);
if(paramValue.length()==0) {
out.println("<TD>"+NoValue+"</TD></TR>");
}
else{
out.println("<TD>"+paramValue+"</TD></TR>");
out.println("</TABLE>");
}
}

out.println("</BODY></HTML>");
out.close();
}

}

My response is :
phone: NoValue entered
email: NoValue entered
lastName: OKUCU
firstName: Engin
But in my ShowMessage.html 'firstName' is the first line and in my response i get it as the last line.
How can I resolve it ?thanks.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that using getParameterNames() to return an enumeration of the parameter names does not specify any order appear within the enumeration. If you want to retrieve and display your parameters in any order you have to use getParameter(String parameterName) to retrieve them one at a time.
 
Engin Okucu
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Drew,
I thank you for your reply. But say, a developer has any knowledge of the parameters in the html page ok? And he wants to retrieve all parameters in a specified order, one at time by order. How has he to do then ? is it possible to do it?
 
You don't know me, but I've been looking all over the world for. Thanks to the help from this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic