How to pass hidden values

There is a row which has 2 fields

<td >燭icket No</td> <td >燘ill No</td>

<td ><input type="text" name="<%= ticketNo+ %>" value="" size=10></td>

<td ><INPUT TYPE="TEXT" NAME="<%=billNo+"%> value="" size=10></td>

I want to pass the values entered in the row along with one hidden value called as rowId. The rowId is attached to the ticketNo and billNo values.

How to do this?.........Plz Help

Any idea , if there are many rows?

[540 byte] By [vishala] at [2007-10-2 8:55:38]
# 1

You can use input of hidden type and place it next to your ticketno or billno input tag.

it will not visible in your page or disturb your table layout when output to browser.

Since it's hidden, you can omit the size="".

<input type="hidden" name="" value="">

Hope it helps.

jbchurna at 2007-7-16 22:59:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks for ur reply.There is a submit button and i want to pass all those values entered along with the hidden row id to the database
vishala at 2007-7-16 22:59:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

All fields of input type text and input type hidden will be sent along with the request when the user submits the form. There is really no difference between a text field and a hidden field other than the fact that the hidden one is not displayed on the page.

So you should be all set. Just use HttpServletRequest.getParameter() to retrieve the values on the server side.

-S-

slenzia at 2007-7-16 22:59:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Slenzi,Can u help me with some sample code or example
vishala at 2007-7-16 22:59:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
The way of getting text/hidden fields is of no difference.Just use - request.getParameter("<your field name>");Remember request is a implicit object in JSP so no need to create new request object.
CT-Banga at 2007-7-16 22:59:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

[nobr]Here is a basic servlet that reads three parameters from a form. One of the is hidden. You can see that its no different from reading non hidden form fields.

-S-

//

// The Servlet

//

package sample;

import javax.servlet.http.*;

import javax.servlet.*;

import java.io.*;

public class TestServlet extends HttpServlet {

private final String CLASS_NAME = "TestServlet";

public void init(ServletConfig config) throws ServletException {

super.init(config);

}

public void doGet(HttpServletRequest req, HttpServletResponse res)

throws ServletException, IOException {

doWork(req,res);

}

public void doPost(HttpServletRequest req, HttpServletResponse res)

throws ServletException, IOException {

doWork(req,res);

}

private void doWork(HttpServletRequest req, HttpServletResponse res)

throws IOException {

String val1 = req.getParameter("Value1");

String val2 = req.getParameter("Value2");

String val3 = req.getParameter("Value3");

System.out.println("Val1: " + val1 + "\nVal2: " + val2 + "\nVal3" + val3);

}

}

//

// JSP Page with hidden fields, posts to our Servlet

//

<html>

<head>

<title>Test Page</title>

</head>

<body>

<form action="/Test" name="" method="Post">

<input type="text" name="Value1" value="This is value 1">

<input type="Hidden" name="Value2" value="This is hidden value 2">

<input type="text" name="Value3" value="This is value 3">

<br>

<input type="Submit" value="Submit Form">

</form>

</body>

</html>

//

// web.xml servlet entry and mapping

//

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app>

<servlet>

<servlet-name>TestServlet</servlet-name>

<servlet-class>sample.TestServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>TestServlet</servlet-name>

<url-pattern>/Test</url-pattern>

</servlet-mapping>

</web-app>

[/nobr]

slenzia at 2007-7-16 22:59:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...