Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Mithrandir

[java] JSP's and POST

This topic is 5532 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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)...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Existing Customers

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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>

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!