• 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

Getting Parameters from form

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am trying to use a HTML form which has a drop down list, where a user selects an entry and the entry gets displayed on the same page when the user presses a 'submit' button. I have managed to do this, but I keep getting a value displayed on the screen before the submit button gets pressed, i.e. a entry appears on the screen when the page first loads! I am not sure why this is - I may need to initialise some variable as blank, but I am not sure which one!
A snippet of my code is given below where a user is asked to select an entry froma drop down list (an application name), then the 'request' object gets the parameters, where I display the 'parameterValue' variable
on the screen. This is the variable that I am trying to get blank before the user submits.
<TD> Please Choose An Application from the Drop down menu</TD>
<TD> <SELECT NAME=App>
<%int k=0;
while(appnames[k]!=null){%>
<OPTION><%=appnames[k]%></OPTION>
<%k++;}%>
</SELECT></TD>
<INPUT TYPE=SUBMIT VALUE=Submit>
<%
Enumeration parameters = request.getParameterNames();
while(parameters.hasMoreElements()){
parameterName = (String)parameters.nextElement();
parameterValue = request.getParameter(parameterName); %>
<TD><%=parameterValue%></TD>

<% } %>
Any ideas anyone??
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If no one option is marked selected, the select element will display the value of the first option. That's standard HTML behavior.
bear
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand it all but I can say one thing. it is no use to
have a Selectbox without any value assigned to the option. How would you know which app the user selected?
 
Mathias Nilsson
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oppps! I've posted without knowing about the above post.
 
Kamal Patel
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I get it not to display anything the first time the page gets loaded?
 
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kamal,
Try This

Cheers
Praful
 
Kamal Patel
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just tried putting the ------select------- entry in, but has not made a difference - still picking up a value. It is like it is caching a value that I selected before I refresh the page!
I think I need some way of saying, don't call the:
Enumeration parameters = request.getParameterNames();
code when the page first loads??
 
Ranch Hand
Posts: 390
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically you did not make all your code available and people are responding based on partial information. I think you are submitting to the same form which makes the parameter value always available to the request. Please paste the whole code including the form tag so people would have enough information to help you out. We might even run the application to know how to tackle the problem.
[ November 10, 2003: Message edited by: Anselm Paulinus ]
 
Praful Thakare
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try clearing your cache by clicking on
Tool->internetoptions->delete files (In case u ar not aware of it)
 
Kamal Patel
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, here is all my code:
<%@ page contentType="text/html" %>

<%--//Page Directives --%>
<%@ page language="java" %>
<%@ page import="javax.xml.parsers.*" %>
<%@ page import="org.w3c.dom.Document" %>
<%@ page import="org.w3c.dom.Element" %>
<%@ page import="org.w3c.dom.DOMException" %>
<%@ page import="java.net.URL" %>
<%@ page import="java.io.InputStream" %>
<%@ page import="java.io.IOException" %>
<%@ page import="logonBean.*" %>
<%@ page import="java.security.*" %>
<%@ page import="java.util.Hashtable" %>
<%@ page import="java.util.Enumeration" %>
<%@ page import="java.util.StringTokenizer" %>
<%@ page import="java.util.*" %>
<%@ page import="javax.naming.*" %>
<%@ page import="javax.naming.directory.*" %>
<%@ page import="javax.servlet.*" %>
<%! public String routeURL="logon.jsp";%>
<%! static String[] appnames = new String[40];%>
<%! int n=0; int flag=0; String name1 = ""; String name2 = ""; String parameterValue = ""; String parameterName="";%>
<%-- //HTML Header --%>

<html>
<head>
<title>Main Page</title>
</head>
<h1>LDAP Server Connection</h1>
<body bgcolor="white">
<FORM ACTION=main.jsp METHOD=POST>
<%-- //Init Page --%>
<%
//#E2EFED
Hashtable env = new Hashtable(5, 0.75f);
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");

/*
env.put(Context.PROVIDER_URL, "ldap://another address/ou=db.com,o=NetscapeRoot");
*/
env.put(Context.PROVIDER_URL, "ldap://address to server/dc=db,dc=com");
try {

DirContext ctx = new InitialDirContext(env);
SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
//insteadof ou=WebSSO, take user input to determine value into variable
NamingEnumeration results = ctx.search("ou=Application", "(ou=*)&& !(ou=App)", constraints);
//boxname=egcilab*

while (results != null && results.hasMore() && flag==0) {
SearchResult si = (SearchResult)results.next();
String name = si.getName();
StringTokenizer st = new StringTokenizer(name, "=");
while(st.hasMoreTokens()){
name1 = st.nextToken();
name2 = st.nextToken();
appnames[n] = name2;
n++;}

/*Attributes attrs = si.getAttributes();
if (attrs == null) {
//out.println("No attributes <br>");
}else{
for (NamingEnumeration ae = attrs.getAll(); ae.hasMoreElements() {
Attribute attr = (Attribute)ae.next();
String attrId = attr.getID();
for (Enumeration vals = attr.getAll();
vals.hasMoreElements();
//out.println(attrId + ": " + vals.nextElement() + "<br>"));
}
}*/

}
flag=1;
//Exception Handling
}//end of try
catch(NamingException e)
{
out.println("Search failed. <br>");
e.printStackTrace();
}
%>
<TR> <TD> Please Choose An Application from the Drop down menu</TD>
<TD> <SELECT NAME=App>
<OPTION>-------Select Value-------</OPTION>
<%
int k=0;
while(appnames[k]!=null){
%>
<OPTION><%=appnames[k]%></OPTION>
<%
k++;
}
%>
</SELECT></TD>
</TR>
<%-- //Page Routing --%>
<INPUT TYPE=SUBMIT VALUE=Submit>
<br><br><br><br>
</FORM>
<HR>
<B>Application selected</B><BR>
<TABLE>
<%
Enumeration parameters = request.getParameterNames();
while(parameters.hasMoreElements()){
parameterName = (String)parameters.nextElement();
parameterValue = request.getParameter(parameterName); %>
<TR>
<%--<TD><%=parameterName%></TD>--%>
<TD><%=parameterValue%></TD>
</TR>
<% }
%>
 
Praful Thakare
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Kamal,
It is working fine for me!!!
I have pasted your code in my file and tried with few changes
Change 1 -
As I the combo box shows me only ---select value-----
I have added <option>--slect valeu1</option>
<option>--slect valeu2</option>
<option>--slect valeu3</option>
then i open new browser and executed this file
the list line of o/p is
Application Selected
Then I select first option and hit submit
last two lines of o/p
Application selected
-------Select Value1-------

then i reopne the browser and type same url with gives me nothing after
Application Selectd
so i Think there is problem with your browser,try with deleting all offline contents.
Cheers
Praful
SORRY FOR LOT OF MISS-SPELLS was in hurry to go home
[ November 10, 2003: Message edited by: Praful Thakare ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic