aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes java.util.Enumeration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "java.util.Enumeration " Watch "java.util.Enumeration " New topic
Author

java.util.Enumeration

Engin Okucu
Ranch Hand

Joined: Feb 09, 2002
Posts: 174
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.
Drew Christensen
Greenhorn

Joined: Sep 25, 2002
Posts: 1
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

Joined: Feb 09, 2002
Posts: 174
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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: java.util.Enumeration