[java] JSP's and POST

Started by
4 comments, last by Mithrandir 20 years, 11 months ago
EDIT: I mean parameters, not attributes. I'm having a problem with my JSP's. For some reason, whenever I have a form that posts data, the post request is received, but there are absolutely no parameters with it.

<td width="44%">Existing Customers:
<table valign=top>
<form method=post action="login.jsp">
<tr><td width="30%">Username:</td><td width="70%"><input type=text name="username"></td></tr>
<tr><td width="30%">Password:</td><td width="70%"><input type=password name="password"></td></tr></table>
<input type="image" src="login.jpg" name="action" value="login">
</td> when the JSP gets parameter"action", there's nothing. In fact, when I enumerate any of the parameters, I get a null Enumeration class. Any ideas? [edited by - Mithrandir on April 28, 2003 4:11:57 PM]
This is my signature. There are many like it, but this one is mine. My signature is my best friend. It is my life. I must master it as I must master my life. My signature, without me, is useless. Without my signature, I am useless.
Advertisement
Do you maybe want to use request.getParameter(name) instead of request.getAttribute(name) ? I know that''s what you would want to use to pull the username/password fields, but I''m not sure what you''re looking for out of the action parameter.

I use attributes of the session object all the time, but I still haven''t found a common use for request attributes (at least for form processing)...
Existing Customers
I meant parameters. sorry.
This is my signature. There are many like it, but this one is mine. My signature is my best friend. It is my life. I must master it as I must master my life. My signature, without me, is useless. Without my signature, I am useless.
If I put this at the top of what you provided and post to the same page...

<%@ page import="java.util.Enumeration" %><b><ul>Parameters<% 	Enumeration enum = request.getParameterNames();	String parm;	while (enum.hasMoreElements())	{		parm = (String)enum.nextElement();		out.print("<li>" + parm + "</li>");	}%></ul></b> 


I get a list showing username, password, action.x, and action.y - could you post a snippet of what you''re using that returns the nulls?

What if you include the parameters in the query string, like http://localhost:8080/login.jsp?action=go - does anything show up then?
Here''s a simple JSP I wrote which just creates a table displaying all the parameters passed to the page.


  <%@ page import="java.util.*" %><!doctype html public "-//w3c//dtd html 4.0 transitional//en" "http://www.w3.org/TR/REC-html40/strict.dtd"><head>    <title>Parameter echo demo</title></head><body><table border="1"><tr><td width="200" align="center">Name</td><td width="200" align="center">Value</td></tr><%Map m = request.getParameterMap();for (Iterator i = m.entrySet().iterator(); i.hasNext(); ){    Map.Entry e = (Map.Entry)i.next();    String name = (String)e.getKey();    String [] vals = (String [])e.getValue();    %>    <tr>    	<td><%= name %></td>    	<td>    	<%    	for (int j = 0; j < vals.length; j++)    	{    	    %><%= vals[j] %><br><%        }        %>        </td>    </tr>    <%}%></table></body></html>  

This topic is closed to new replies.

Advertisement