aspose file tools*
The moose likes JSP and the fly likes how in JSP I translate an html checkbox to true/false in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "how in JSP I translate an html checkbox to true/false in java" Watch "how in JSP I translate an html checkbox to true/false in java" New topic
Author

how in JSP I translate an html checkbox to true/false in java

Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
how in JSP I translate an html checkbox to true/false in java?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Is this a question, or an answer? (Besides being something I'd generally write in a single line.)
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
Question, i think always gives false either...?

(Integer.parseInt(request.getParameter("accidentalCover")) == 1)
request.getParameter("accidentalCover").equals("checked"))
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Well, the "checked" thing certainly makes no sense--look at what's coming in... *frown*

If it isn't coming in at all, as in the case of an unchecked box, what will Integer.parseInt(...) do? Does it throw an exception?

Have you looked at the actual request (via Firebug, a proxy, or whatever) to make sure it's being sent as you expect?
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
Generally speaking checkboxes in Java6 how handled? I replaced with two row, drop down menu,and worked success...
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Either the way you're doing it, or by sending a "true" or "false", or by sending "checked", or...

There is no "general" way.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61057
    
  66

HTML checkboxes have nothing to do with Java, 6 or otherwise. They work very simply: if they are checked, their name/value pair is included in the submission, if not checked no information is included in the submission. Simple as that.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
how to check in java if webuser indeed check the tick or not ?

request.getParameter("accidentalCover")==null; // true if not checked?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61057
    
  66

That's what David and I have said. If the box is unchecked, no parameter.
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
Bear Bibeault wrote:That's what David and I have said. If the box is unchecked, no parameter.


no parameter=null?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61057
    
  66

Try it and let us know what you find.
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403


// above jsp:expression[since jspx file] gives 1 or null and now working...success
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Why are you doing Java programming in your JSPs? That should be in a servlet (or whatever back-end framework you're using).
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
is anyway, correct if you find difficult with servlets...?
just hence the book references JSPs, and servlets need param in web.xml...etc...

Q:
call to session.invalidate(); must also more correctly done in servlet, after get the session var...from httprequest...?

how to check if session.invalidate(); executed coorrect?

how rather all session, only a session bean obj(contents objs&vars) only need to nulled, how?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Leonidas Savvides wrote:how to check if session.invalidate(); executed coorrect?

You don't: you assume your container actually works.
how rather all session, only a session bean obj(contents objs&vars) only need to nulled, how?

Set the attribute to null.
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
David Newton wrote:
Leonidas Savvides wrote:how to check if session.invalidate(); executed coorrect?

You don't: you assume your container actually works.
how rather all session, only a session bean obj(contents objs&vars) only need to nulled, how?

Set the attribute to null.


if attribute is object(eg. cart), that contains vars and other objects(eg lineItems)?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Think: the only way you access the cart is via a "cart" object in the session. If you retrieve the "cart" object, and it's null, what else is left to do?
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
if NOT null, how assign an obj cart to null and sub-objs too[lineItems]...?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617



session.setAttribute("cart", null);

What makes you think you need to set each line item to null?
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
if a have servlets and jsps and the cart declared as session bean in a JSP, how get the obj shopping cart cart [in session.setAttribute("cart", null);] to the servlet and execute
session.setAttribute("cart", null);
?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617



Look at the API for HttpServletRequest and see if there's anything relating to the session.

I think you should really take a step back and focus on some Java web application basics before proceeding much further; it'll really help you in the long run.
Leonidas Savvides
Ranch Hand

Joined: Jan 31, 2010
Posts: 403
I tried
<jsp:useBean id="AddChoosePlant" scope="page" class="beans.OrderTotals" /> // shopping cart bean with sub beans line items

session.setAttribute("AddChoosePlant", null);
if (session.getAttribute("AddChoosePlant")==null){
run what is here...

but seems sub objects not get to null....?

may use a function to bean makes all subobjects(sub beans) nulls?
Is any way this achived via the jsp or servlet (above code is in jsp)...?
 
Consider Paul's rocket mass heater.
 
subject: how in JSP I translate an html checkbox to true/false in java