Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.util.Enumeration

 
Engin Okucu
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • 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.
 
Drew Christensen
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic