This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how in JSP I translate an html checkbox to true/false in java?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this a question, or an answer? (Besides being something I'd generally write in a single line.)
 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question, i think always gives false either...?

(Integer.parseInt(request.getParameter("accidentalCover")) == 1)
request.getParameter("accidentalCover").equals("checked"))
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally speaking checkboxes in Java6 how handled? I replaced with two row, drop down menu,and worked success...
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what David and I have said. If the box is unchecked, no parameter.
 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try it and let us know what you find.
 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


// above jsp:expression[since jspx file] gives 1 or null and now working...success
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if NOT null, how assign an obj cart to null and sub-objs too[lineItems]...?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


session.setAttribute("cart", null);

What makes you think you need to set each line item to null?
 
Leonidas Savvides
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)...?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!