[Logo]
Forums Register Login
Hidden field can carry any type of java objects ?
I need to use hidden variable to carry some big objects (like very long arraylist, String[][]), is there any known issue or restriction for hidden variable to carry such objects ?
You can store objects that you have described in a single hidden field.

Better you put in to session, if you to pass those objects to the next link.
 

You can store objects that you have described in a single hidden field.



No, you can't. Like all other input types, you are restricted to strings.
I'm guessing you are you talking about hidden FORM fields? The concept of "hidden" applies only as a flag to the browsers HTML rendering engine... the browser has no concept of Java objects!!!
sorry, to clarify, I was talking about hidden form field like
<FORM ACTION="/myaction" >

<type="radio" name="..", value="..">...
....

<type="HIDDEN" name="hidden_obj" value="<%= request.getAttribue("obj") %>">

</FORM>

So, I do want to get an object passed. Can I do that this way ?
No, you can't put an object there at all. Just a string. Remember what the <%= operator does, it prints out a String. Now Java has a little feature, where if you try and print out an object, it automatically calls the objects toString() function.

So what you have to do if you really want to do this, is convert it to a string, for example using ";" characters to seperate each string in the array. Then you have to read the string back in and create the objects from it again, for example using a StringTokenizer.

Other things you can consider are like said above, putting the objects on the Session object.

Perhaps just putting an 'id' in a hidden field, which refers to an item in a structure which is held at the application level.
thanks folks. So, it seems the only way to carry the "objects" over pages is to use "session" ? I am wondering how people handle such things when "HttpSession" was not available to java developers ? Furthermore, how do those ASP, Cold fusion people do it ? interesting.
Why wouldn't you have a session or be unable to create one?
If you have an Http server you have sessions, they're not some magical Java feature that some servers have and other don't.

Read up on the servlet specification and the HTTP specifications, you might learn a thing or two.
 

Originally posted by Jeroen Wenting:
Why wouldn't you have a session or be unable to create one?
If you have an Http server you have sessions, they're not some magical Java feature that some servers have and other don't.

Read up on the servlet specification and the HTTP specifications, you might learn a thing or two.



I was just asking questions about "hidden fields", and I guess it has nothing to do with "whether session is better or can I use session ?"

This thread has been viewed 5639 times.

All times above are in ranch (not your local) time.
The current ranch time is
Oct 18, 2018 10:43:24.