• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

form action question???

 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, for a form action, I want to redirect a page to itself, passing parameters. The problem is that the name of the page will be dynamic or generic where I wont be able to tell wehta the name is.
For example a page called test.jsp
has a line that is liek the following...
<form action="">
The action will return to this same page. That is fine but I want to be able to pass pararameters like
<form action="test.jsp?name=Anthony">

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi buddy,
Try this example which i have made this may help you. As it displays the results on the same page.
<%@ page errorPage="error.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Generating Table </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY bgcolor=#FFCCFF>
<center>
<h1><font color="red">Colorful and Dynamic Table</font></h1>
<form method=post action="Table.jsp?name=Anthony">
<table>
<tr>
<td colspan="2"> <font size="2">
<%
int width=15;
int height=15;
%>
<font face="Arial, Helvetica, sans-serif"><b>Table width (Less than
16) =</b>
<input type=text name=width value=<%=width%> size=2>
, </font></font></td>
</tr>
<tr>
<td colspan="2"> <b><font face="Arial, Helvetica, sans-serif" size="2">Table
Height (Less than 16) = </font></b>
<input type=text name=height value=<%=height%> size=2>
, </td>
</tr>
<tr>
<td><font face="Arial, Helvetica, sans-serif" size="2"><b>Select color
: -</b></font></td>
<td>
<select name="select">
<option value="#00FFFF" selected>Not specified</option>
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
<option value="Pink">Pink</option>
</select>
</td>
</tr>
<tr>
<td align=center colspan="2">
<input type=submit value="Click me Buddy !">
</td>
</tr>
</table>
</form>
<hr noshade>
<%
String w =request.getParameter("width");
String h= request.getParameter("height");
String col= request.getParameter("select");
if(w==null) w="15";
else w=request.getParameter("width");
if(h==null) h="15";
else h=request.getParameter("height");
if(col==null) col="#00FFFF";
else col=request.getParameter("select");
width = Integer.parseInt(w);
height = Integer.parseInt(h);
//if(width>15) width=15;
//if(width<0) width=0;
//if(height>15) height=15;
//if(height<0) height=0;
String[] colorArray={"00","11","22","33",
"44","55","66","77","88","99",
"AA","BB","CC","DD","EE","FF"};
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0" bordercolor="#CCCCCC" bgcolor=<%=col %>>
<tr>
<td align="center">
<table border=0 cellpadding =2 cellspacing=2>
<%
try {
%>
<%for (int y=0;y<=height;y++){%>
<tr>
<% for(int x=0;x<=width;x++) {
String bgColor="AA"+colorArray[y]+ colorArray[x];
%>
<td bgcolor=<%=bgColor%>> (<%=x%>,<%=y%> ) </td>
<%}%>
</tr>
<%}%>
<%
}
catch(Exception e)
{
out.print("<p align=justify><b>Please insert appropriate values. There is an Exception in your program which is :-"+e+"</b></p>");
}
%>
</table>
</td>
</tr>
</table>
<p>This is the following information which has been submitted to the server :-<br>
<b>This is width of the table :- <%=request.getParameter("width")%></b><br>
<b>This is heigth of the table :- <%=request.getParameter("height")%></b><br>
<b>This is bgcolor :- <%=request.getParameter("select")%></b><br>
</p>
<hr noshade>
</center>
</BODY>
</HTML>

The error page which i am printing is
<%@ page isErrorPage="true" import="java.io.*" %>
<HTML>
<HEAD>
<TITLE>This is my error </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY bgcolor="beige">
<h1 align=center>We have an error message here <%=request.getRemoteHost();%></h1>
<table border=1>
<tr>
<td>Exception</td>
<td><b><%=exception%></b></td>
</tr>
<tr>
<td>Message</td>
<td><b><%=exception.getMessage()%></b></td>
</tr>
<tr>
<td>Localized Messege</td>
<td><%=exception.getLocalizedMessage()%></td>
</tr>
<tr>
<td>Stack Trace</td>
<td><pre>
<%
StringWriter sw =new StringWriter();
PrintWriter pw=new PrintWriter(sw);
exception.printStackTrace(pw);
out.println(sw);
%></pre>
</td>
</tr>
</table>
<center><a href="javascript:history.back(0)">Please Enter your values again</a></center>
</BODY>
</HTML>
Use this two import the error page so that it also handles th exception. I hop ethi shelps you
abhinav
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd be wary about trying to pass data by including it in the form action attribute, since from experience its support is browser dependant: Some keep it and some just ignore it.
You are better off including it as a hidden field.
Dave.
 
What's that smell? I think this tiny ad may have stepped in something.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic