Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

A minor error involving JSP

Posted on 2004-10-06
5
Medium Priority
?
237 Views
Last Modified: 2011-09-20
I got this jsp example from the internet but the problem is that, it can not show some fields like firstname, lastname, address etc. To my surprise again it can show fields starting from state downwards. So i was wondering if you could help me figure out the problem.

 <% @ page import="java.util.";%>
  <% @ page language="java"%>
   
H <HTML><HEAD><TITLE>Dynamic Form</TITLE></HEAD>
  <BODY>
  <B>Form</B>
  <FORM ACTION=dynamicForm.jsp METHOD=POST>
  <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>
  <%  String[] textFields = {"FirstName","LastName","Address","City","Zip"};
     for(int j=0; j<textFields.length; j++){     %>
     <TR>    <TD> <%=textFields[j]%>:                       </TD>
              <TD> <INPUT TYPE=TEXT NAME=<%=textFields[j]%>> </TD>
     </TR>
  <%  }   %>
     <TR>    <TD> State  </TD>
             <TD> <SELECT NAME=State>
  <%  String[] states = {"AZ", "CA", "NM", "MA", "ME", "MD", "..."};
      for(int s=0; s<states.length; s++) {    %>
                     <OPTION><%=states[s]%></OPTION>
  <%  }   %>
                  </SELECT></TD>
     </TR>
     <TR>    <TD> Card Number  </TD>
             <TD> <INPUT TYPE=TEXT NAME=cNumber></TD>
     </TR>
     <TR>    <TD> Card Type  </TD>
             <TD> <SELECT NAME=CardType>
  <%  String[] cTypes = {"Amex", "Visa", "Master Card", "Discovery", "..."};
     for(int t=0; t<cTypes.length; t++) {    %>
                     <OPTION><%=cTypes[t]%></OPTION>
  <%  }   %>
                  </SELECT></TD>
     </TR>
     <TR>    <TD> Expiration Date (MM/DD/YYYY) </TD>
    <TD> <INPUT TYPE=TEXT NAME=cMonth SIZE=2><INPUT TYPE=TEXT NAME=cDay SIZE=2>
             <SELECT NAME=cYear>
             <%  int startYear = 2000;
                 int endYear = 2010;
                 for(int y=startYear; y<endYear; y++) {    %>
                     <OPTION><%=y%></OPTION>
            <%  }   %>
             </SELECT></TD>
     </TR>
  </TABLE>
     <INPUT TYPE=SUBMIT VALUE=Submit>
  </FORM>
  <HR>
  <B>Form Content</B><BR>
  <TABLE>
  <%  Enumeration parameters = request.getParameterNames();
      while(parameters.hasMoreElements()){
         String parameterName = (String)parameters.nextElement();
         String parameterValue = request.getParameter(parameterName); %>
        <TR>
             <TD><%=parameterName%></TD>
             <TD><%=parameterValue%></TD>
         </TR>
  <%  }   %>
  </BODY></HTML>
0
Comment
Question by:pkeketso
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 33

Accepted Solution

by:
sajuks earned 200 total points
ID: 12235462

<%@ page import="java.util.*" %>
  <%@ page language="java"%>
   
H <HTML><HEAD><TITLE>Dynamic Form</TITLE></HEAD>
  <BODY>
  <B>Form</B>
  <FORM ACTION=dynamicForm.jsp METHOD=POST>
  <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>
  <%  String[] textFields = {"FirstName","LastName","Address","City","Zip"};
     for(int j=0; j<textFields.length; j++){     %>
     <TR>    <TD> <%=textFields[j]%>:                       </TD>
              <TD> <INPUT TYPE=TEXT NAME=<%=textFields[j]%>> </TD>
     </TR>
  <%  }   %>
     <TR>    <TD> State  </TD>
             <TD> <SELECT NAME=State>
  <%  String[] states = {"AZ", "CA", "NM", "MA", "ME", "MD", "..."};
      for(int s=0; s<states.length; s++) {    %>
                     <OPTION><%=states[s]%></OPTION>
  <%  }   %>
                  </SELECT></TD>
     </TR>
     <TR>    <TD> Card Number  </TD>
             <TD> <INPUT TYPE=TEXT NAME=cNumber></TD>
     </TR>
     <TR>    <TD> Card Type  </TD>
             <TD> <SELECT NAME=CardType>
  <%  String[] cTypes = {"Amex", "Visa", "Master Card", "Discovery", "..."};
     for(int t=0; t<cTypes.length; t++) {    %>
                     <OPTION><%=cTypes[t]%></OPTION>
  <%  }   %>
                  </SELECT></TD>
     </TR>
     <TR>    <TD> Expiration Date (MM/DD/YYYY) </TD>
    <TD> <INPUT TYPE=TEXT NAME=cMonth SIZE=2><INPUT TYPE=TEXT NAME=cDay SIZE=2>
             <SELECT NAME=cYear>
             <%  int startYear = 2000;
                 int endYear = 2010;
                 for(int y=startYear; y<endYear; y++) {    %>
                     <OPTION><%=y%></OPTION>
            <%  }   %>
             </SELECT></TD>
     </TR>
  </TABLE>
     <INPUT TYPE=SUBMIT VALUE=Submit>
  </FORM>
  <HR>
  <B>Form Content</B><BR>
  <TABLE>
  <%  Enumeration parameters = request.getParameterNames();
      while(parameters.hasMoreElements()){
         String parameterName = (String)parameters.nextElement();
         String parameterValue = request.getParameter(parameterName); %>
        <TR>
             <TD><%=parameterName%></TD>
             <TD><%=parameterValue%></TD>
         </TR>
  <%  }   %>
  </BODY></HTML>
   

<HTML><HEAD><TITLE>Dynamic Form</TITLE></HEAD>
  <BODY>
  <B>Form</B>
  <FORM ACTION=dynamicForm.jsp METHOD=POST>
  </BODY></HTML>
0
 
LVL 33

Expert Comment

by:sajuks
ID: 12235464
notice this change
<%@ page import="java.util.*" %>
  <%@ page language="java"%>
0
 
LVL 33

Expert Comment

by:sajuks
ID: 12235501
Also you cannot ensure the order of the parameters being submitted .
You have to use something like
  if (parameterName .equals("param1"))
<TD><%=parameterName%></TD>
            <TD><%=parameterValue%></TD>

}

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
On September 18, Experts Exchange launched the first installment of the Help Bell, a new feature for Premium Members, Team Accounts, and Qualified Experts. The Help Bell will serve as an additional tool to help teams increase question visibility.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question