Retrieving checkbox values from JSP

In my program I have an 'ADD' form.
In that form I ask the question "Do you have a car?"
with a single checkbox for reply.
The code I use is below.
Can anyone tell me how to set the checkbox to 'ticked' or 'unticked' in my
main jsp by sending paramters from the ADD form's checkbox??
ADD FORM...
<form action='post' method='servlet/controller?task=addEmployee'>
<input type'text' name='emplpoyee'>
<input type='checkbox' name='car' value='true'>
<input type='submit' name='submit' value='Add'>
</form>
Through a class I retrieve the values posted
public Page doTask() {
Employees employee = new Employees();
employee.setName(request.getParameter("name"));
employee.setCar(Boolean.getBoolean(request.getParameter("car")));
try{
String submit = request.getParameter("submit");
if(submit.equals("Add")){
model.addEmployee(employee);
Page nextPage = new Page("/servlet/Controller?task=GetAllEmployeesTask");
return nextPage;
This class sends the parameters to my main JSP where
this information is inserted. ('employees.jsp')
my name is retrieved so...
<= employees.getName()>
how would I retrieve/set a checkbox value

request.getParameter("car")
the thing is that the browser will not send unchecked checkbox values. so you can only know it was checked by the presense or absense of the value.

Similar Messages

  • Can't retrieve bean value from jsp!

    Here's the chain of events for my web app:
    JSP form (get info from user) -> forwarding jsp (uses bean to save info submitted to form)-> servlet (retrieves info from DB) -> JSP (presents DB info to user by populating values in text fields from original form)
    Right now, I can access all the values submitted to the first JSP from my servlet. However, after my servlet retrieves the info from a db and stores it in a bean and forwards the request (using requestdispatcher) to the 2nd JSP, I can't get the values from the bean from the 2nd jsp. I was able to use the bean to store the information submitted to the original JSP, however.
    Here's some relevant code:
    FROM FORWARDING JSP (which saves user-submitted info in bean)
    <jsp:useBean id="fxFormBean" class="fxmatcher.FxFormBean" scope="request"/>
    <jsp:setProperty name="fxFormBean" property="*" />
    <jsp:forward page="/FxMatcher" />
    FROM LAST JSP (which should populate form fields)
    header stuff:
    <jsp:useBean id="fxFormBean" class="fxmatcher.FxFormBean" scope="session"/>
    info retrieval:
    <INPUT TYPE="text" NAME="fx_key" value="<%= fxFormBean.getFx_key() %>">
    I wrote this JSP based on the example given here: http://www.jsptut.com/Editing.jsp, but I'm not getting the value from the bean. The result JSP just has value="".
    I'm pretty sure that my servlet is saving the info to bean correctly, but here's the code anyways:
    //retrieves info from DB
    FxFormBean fx = (FxFormBean) request.getAttribute("fxFormBean");
    fx.setFx_key (traderKey);
    fx.setAa_block(agent_block);
    fx.setAddition_to (additional_to);
    log("trader key: [" + fx.getFx_key() + "]"); //debugging code
    My debugging code did print out the correct info, so I don't think there's anything wrong with the bean or the servlet.
    I would appreciate any help. Thank you very much.

    The first JSP puts the bean in the request, the servlet retrieves the bean from the request and updates it but in the second JSP you set the scope to session:
    <jsp:useBean id="fxFormBean" class="fxmatcher.FxFormBean" scope="session"/>
    So the second JSP is looking in the wrong place for your bean. Change the scope in the second JSP to request:
    <jsp:useBean id="fxFormBean" class="fxmatcher.FxFormBean" scope="request"/>

  • Re: [iPlanet-JATO] Re: Retrieving all Values from a Tiled View

    Todd,
    Let me try to explain you this time. I have a text field in a TiledViewBean.
    When I display the page, the text field
    html tag is created with the name="PageDetail.rDetail[0].tbFieldName" say
    five times/rows with same name.
    The html tags look like this.
    <input type=text name="PageDetail.rDetail[0].tbFieldName" value=""
    maxlength=9 size=13>
    <input type=text name="PageDetail.rDetail[0].tbFieldName" value=""
    maxlength=9 size=13>
    <input type=text name="PageDetail.rDetail[0].tbFieldName" value=""
    maxlength=9 size=13>
    When the form is submitted, I want to get the text field values using the
    method getTbFieldName().getValues() which
    returns an array object[]. This is in case where my TiledViewBean is not
    bound and it is working fine.
    Now in case when my TiledView is bound to a model, it creates the html tags
    as follows.
    <input type=text name="PageDetail.rDetail[0].tbFieldName" value=""
    maxlength=9 size=13>
    <input type=text name="PageDetail.rDetail[1].tbFieldName" value=""
    maxlength=9 size=13>
    <input type=text name="PageDetail.rDetail[2].tbFieldName" value=""
    maxlength=9 size=13>
    Now when I say getTbFieldName().getValues() it returns only the first
    element values in the object[] and the rest of the
    values are null.
    May be we need to create a utility method do get these values from
    requestContext.
    raju.
    ----- Original Message -----
    From: Todd Fast <toddwork@c...>
    Sent: Saturday, July 07, 2001 3:52 AM
    Subject: Re: [iPlanet-JATO] Re: Retrieving all Values from a Tiled View
    Raju.--
    I wanted to know how the getValues() method works the reason being,
    when the tiled view is NOT bound to a model, it populates all the
    fields with the same name as some thing likeI'm afraid I don't understand your point--can you please clarify? Do you
    mean "value" instead of "name"?
    What are you trying to do? What behavior are you expecting but notseeing?
    >
    Without further clarification, I can say that the setValues() methodsNEVER
    populates data on multiple rows of a (dataset) model, nor does it affect
    multiple fields on the same row. Perhaps what you are seeing is theeffect
    of default values. Model that derive from DefaulModel have the ability to
    carry forward the values set on the first row to other rows in lieu ofdata
    in those other rows. This behavior is for pure convenience and can be
    turned off, and it is turned off for the SQL-based models.
    Todd
    [email protected]

    Hi,
    I wanted to know how the getValues() method works the reason being,
    when the tiled view is NOT bound to a model, it populates all the
    fields with the same name as some thing like
    PageDetail.rDetail[0].tbFieldValue
    PageDetail.rDetail[0].tbFieldValue
    in which case, the getValues() method works fine.
    But in case where the tiled view is bound to a model, it populates
    with different field names such as,
    PageDetail.rDetail[0].tbFieldValue
    PageDetail.rDetail[1].tbFieldValue
    in this case, the getValues() doesn't work. Any soultion to this?
    We are using Moko 1.1.1.
    thanks in advance,
    raju.
    --- In iPlanet-JATO@y..., "Todd Fast" <toddwork@c...> wrote:
    Does anyone know of is there a single method to get all values of a
    display
    field in a tiled view without having to iterate through all the
    values ie
    resetTileIndex() / nextTile() approach.
    ie Something that returns an Object[] or Vector just like ND returned a
    CspVector. I tried using the getValues() methods but that allways returns
    a
    single element array containing the first element.
    (I think now, that method is used for multi selecteable ListBoxes)Actually, no. We can add this in the next patch, but for now, I'd recommend
    creating a simple utility method to do the iteration on an arbitrary model
    and build the list for you.
    Todd

  • How to get Checkbox Value from Flex in PHP.

    Hi,
    I need to know how to get a checkbox value from flex in PHP-POST/GET because I don't know what is the value property of a checkbox in flex.
    Please Help.

    Hi,
    It is very simple. Follow the steps below to achieve the solution,
    1. Write a check-box change event to capture the value of the check box. Store this value in a variable(say bolChkSelected:Boolean).
    2. In step 1 you got the value of the check box. Now your aim is to send the value to php. Declare a httpService in your flex application(i think you are aware of using it).Ok..im writing it
    <mx:HTTPService id="sampleService" resultFormat='e4x' url='http://yourdomain/file.php' result='handleResult()' fault='handleFault()'>
    </mx:HTTPService>
    3. Now the actual solution... u need to send the shcStatus in to php..
    Declare an object to hold the data
    var objparameters:Object={};
    objparameters['CheckBoxdata'] = bolChkSelected;
    --in the above line... 'CheckBoxdata' is used as a parameter to php..you shud have the same variable name while accessing in php file also..
    in php file..
    checkboxstatus = $_POST[''CheckBoxdata''];
    echo checkboxstatus
    thats it..

  • How to retrieve 2 values from a table in a LOV

    Hi
    I'm pretty new to APEX. I try to retrieve two values from a table using a LOV. I have a table named DEBIT with then columns SITE, NAME and KEY
    I want to display NAME to the user in a list. When the user select an item from the list, I want to retrieve the data of the SITE and KEY column of this item in order to launch an SQL command based on this two values.
    How to retrieve thes two values whant the user chooses an item from the list ?
    I apologize for my english, being french.
    Regards.
    Christian

    Christian,
    From what I understood about your requirement, you want a 'select list with submit' which displays "NAME" and based on the value selected, you want to get the corresponding values for "SITE" and "KEY" from the table.
    <b>Step 1: Create a select list with submit, say P1_MYSELECT </b><br><br>
    Use something like this in the dynamic list of values for the select list: <br>
    SELECT NAME display_value, NAME return_value
    FROM DEBIT<br><br>
    <b>Step 2: Create a page process of type PL/SQL block. Also create 2 hidden items P1_KEY and P1_SITE. </b><br><br>
    In the PL/sQL, write something like:
    DECLARE
      v_key DEBIT.KEY%TYPE;
      v_site DEBIT.SITE%TYPE;
      CURSOR v_cur_myvals IS
              SELECT KEY, SITE
              FROM DEBIT
              WHERE NAME = :P1_MYSELECT;
    BEGIN
      OPEN v_cur_myvals;
      LOOP
              FETCH v_cur_myvals
              INTO  v_key,v_site;
              EXIT WHEN v_cur_myvals%NOTFOUND;
    :P1_KEY := v_key;   
    :P1_SITE := v_site; 
      END LOOP;
      CLOSE v_cur_myvals;
    END; <br><br>
    Then you can use these values for whatever purpose you need to.
    Hope this helps.

  • Values from JSP to Struts Action Class

    Dear All,
    Am working on a small struts project, i want to get values from JSP in the Action class, i tried with sending variables using request through URL, it works fine, any other way is there to send the values from JSP to action class. Am not having any input fields in the JSP.I have links.
    Thanks,
    vyrav.

    I have a dispatch action for that am calling the action like this viewfiles.do?parameter=edit, and i have to send a variable ID from the same page, so am doing like this through java script, viewfiles.do?parameter=edit&id=10. Am able to get the id in the dispatch action edit, but when i start tomcat with security manager its not calling the action itself and its giving accesscontrol exception, but when i directly type viewfiles.do in URL its calling the action.
    I dont know wats the problem, tomcat security manager not allowing this. Please help me.
    Thanks,
    vyrav.

  • Retrieving all values from hashmap in order you put them in

    Hi guys,
    I want to retrieve all values from a HashMap in the order I put them in.
    So I can't use the values() method that gives back a collection and iterate over that.
    Do you guys know a good way to do that ?

    You can just do something like this:
    class OrderedMap
        private final Map  m_rep = new HashMap();
        private final List m_keys = new ArrayList();
        public Object get( final Object key )
            return m_rep.get( key );
        public Object put( final Object key, final Object value )
            final Object result = m_rep.put( key, value );
            if ( result != null )
                m_keys.add( key );
            return result;
        public Object remove( final Object key )
            final Object result = m_rep.remove( key );
            if ( result != null )
                m_keys.add( key );
            return result;
        public Iterator keyIterator()
            return m_rep.iterator();
    }Then use it like this:
       for ( Iterator it = map.keyIterator(); it.hasNext(); )
           final Object value = map.get( it.next() );
       }This will be in the order you put them in. However, if you want to do this correctly, you should implement the Map interface and add all the methods. Another thing you can do is download the JDK 1.4 source, learn how they did and do it the same way for 1.2.
    R.

  • How to retrieve the values from a table if they differ in Unit of Measure

    How to retrieve the values from a table if they differ in Unit of Measure?

    If no data is read
    - Insure that you use internal code in SELECT statement, check via SE16 desactivating conversion exit on table T006A. ([ref|http://help.sap.com/saphelp_nw70/helpdata/en/2a/fa0122493111d182b70000e829fbfe/frameset.htm])
    If no quanity in result internal table
    - There is no adqntp field in the internal table, so no quantity is copied in itab ([ref|http://help.sap.com /abapdocu_70/en/ABAPINTO_CLAUSE.htm#&ABAP_ALTERNATIVE_1@1@]).
    - - Remove the CORRESPONDING, so quantity will fill the first field adqntp1.  ([ref|http://help.sap.com/abapdocu_70/en/ABENOPEN_SQL_WA.htm])
    - - Then loop at the internal table and move the quantity when necessary to the 2 other fields.
    * Fill the internal table
    SELECT msehi adqntp
      INTO TABLE internal table
      FROM lipso2
      WHERE vbeln = wrk_doc1
        AND msehi IN ('KL','K15','MT').
    * If required move the read quantity in the appropriate column.
    LOOP AT internal_table ASSIGNING <fs>.
      CASE <fs>-msehi.
        WHEN 'K15'.
          <fs>-adqnt2 = <fs>-adqnt1.
          CLEAR <fs>-adqnt1.
        WHEN 'MT'.
          <fs>-adqnt3 = <fs>-adqnt1.
          CLEAR <fs>-adqnt1.
      ENDCASE.
    ENDLOOP.
    - You could also create another table with only fields msehi and adqntp and then collect ([ref|http://help.sap.com/abapdocu_70/en/ABAPCOLLECT.htm]) the data to another table.
    Regards,
    Raymond

  • How to retrieve the values from PL/SQL table types.

    Hi Every one,
    I have the following procedure:
    DECLARE
    TYPE t1 IS TABLE OF emp%ROWTYPE
    INDEX BY BINARY_INTEGER;
    t t1;
    BEGIN
    SELECT *
    BULK COLLECT INTO t
    FROM emp;
    END;
    This procedure works perfectly fine to store the rows of employee in a table type. I am not able to retrieve the values from Pl/SQL table and display it using dbms_output.put_line command.
    Can anybody help me please!!!!!
    Thanks
    Ahmed.

    You mean, you can't add this
    for i in t.first..t.last loop
    dbms_output.put_line(t(i).empno||' '||t(i).ename||' '||t(i).job);
    end loop;or you can't add this
    set serveroutput onor maybe, you are working in third party application where dbms_output is not applicable at all?
    You see, not able like very similar it is not working - both are too vague...
    Best regards
    Maxim

  • Passing value from JSP to JApplet

    Hello,
    I am stuck up with a problem, can anyone please tell me how do i pass a value from a JSP page
    to a JApplet,
    and the parameter passed through JSP should be displaed in the JTextArea.
    It would be kindful if any of you could help.
    Thanks
    Sanam

    hello,
    thanks for reply.
    I know how to pass parameters from html,
    I want to pass values from jsp page,
    and i dono how to do it, may be we cann pass values through url connection but i dono how.
    if anone knows plz help me in solving this.
    i hvae posted my applet code.
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.JToolBar;
    import javax.swing.JButton;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.JScrollPane;
    import javax.swing.JPanel;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    import java.sql.*;
    <applet code = "DocApplet" width = 500 height =5000>
    </applet>
    public class DocApplet extends JApplet
         private JPanel jp;
         private Container cp;
         private JTextArea jt;
         private JToolBar tb;     
         private JScrollPane sp;
         private String annotation;
         private String url;
         private Connection con;
         private Statement stmt;
         public void init()
              jp = new JPanel();
              cp = getContentPane();
              jt = new JTextArea();
              tb = new JToolBar();
              sp = new JScrollPane(jt);
              repaint();
         public void start()
              jp.setLayout(new BorderLayout());
              jp.add(tb, BorderLayout.NORTH);
              jp.add(sp, BorderLayout.CENTER);
              jt.setBackground(Color.BLACK);
              jt.setForeground(Color.WHITE);
              setContentPane(jp);
              addButtons(tb);
              repaint();
         public void run()
              repaint();
         public void paint()
         private void addButtons(JToolBar tb)
              JButton button = null;
              button = new JButton("Save");
              button.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
              tb.add(button);
    }

  • Passing value from JSP to scriptlet

    Hi
    I am trying to find a way to pass a value from jsp to the scriptlets, i.e.
    <c:set var="testValue" value="123" />
    <%
    System.out.println(testValue);
    %>
    the above code just demonstrates what I was trying to achieve, by passing the value from the jsp into the scriptlet.
    Can someone tell me if there's an easy way to do this?
    Thank you.

    Note, using scriptlet code on your page is generally something to be avoided. 99% of what you should be doing on a JSP page can be done with EL/JSTL. If you can't do it with EL/JSTL then it probably belongs in a servlet/bean.
    I always aim for 100% scriptlet free jsp pages.
    Having said that, I can still answer your question: EL attributes are stored in the scope - page, request, session, application
    ${testValue} is equivalent to pageContext.findAttribute("testValue").
    The <c:set> tag example doesn't specify a scope, so therefore you could get it like this:
    <c:set var="testValue" value="123" />
    <%
    String testValue = (String)pageContext.getAttribute("testValue");
    System.out.println(testValue);
    %>alternatively exploit the feature of the useBean tag that creates a scriptlet variable:
    <c:set var="testValue" value="123" />
    <jsp:useBean id="testValue" type="java.lang.String"/>
    <%
    System.out.println(testValue);
    %>Note that the EL variable and the Scriptlet variable are initially pointing at the same String.
    But changing the string in scriptlet code will change the value it is pointing at, while leaving the EL variable untouched.
    If you have a List in scope, and sharing it between EL and scriptlet variables then any changes to the list would be reflected because they both point at the same List object.
    cheers,
    evnafets

  • Has anyone retrieved a value from a system Matrix from selecting the row

    Hi everyone, I am trying to retrieve the value of a cell from the first column of a matrix depending on which row the user has highlighted.  I can access the value from specifying which row to retrieve the value from but not from the user selecting which row.   Im attempting do do this from the open items list system form which is accessed from the reports menu. 
    To retrieve the value from the first row my code is as follows:
    oMatrix = oForm.Items.Item("5").Specific
    DocNo = oMatrix.Columns.Item("1").Cells.Item(1).Specific.Value
    SBO_Application.MessageBox(DocNo)
    How do I change this code to access the value of the cell depending on which row is highlighted?
    Any help would be appreciated

    Hi Sally,
    you will get the selected row number on any event through "pVal.Row", you can get this value in a integer variable like:
    int i = pVal.Row
    and pass it in your code;
    DocNo = oMatrix.Columns.Item("1").Cells.item(i)
    or you can do same in this way also:
    you have to specify your particular cell as a edit text and get the value of that:
    oEditText=(SAPbouiCOM.EditText)oMatrix.Columns.Item("1").Cells.Item(i).Specific;
    string1 = oEditText.String;
    Hope it will help.

  • How to pass value from jsp to java bean

    I have huge problem . How to pass value from jsp value to java bean.Please replay me soon

    Use the <jsp:setProperty> tag. There are several ways to use it. The one you probably want is:
    <jsp:setProperty name="bean_name"  property="property_name"  value="the_value_you_want_to_set"/>

  • How to retrieve attribute value from my JSP?

    My servlet needs to redirect to a JSP. Before that, I set an attribute value.
    getServletContext().setAttribute("filename",templateFile);
    RequestDispatcher rd = getServletContext().getRequest...
    rd.forward(request, response);
    In my JSP, this is how I want to retrieve it:
    <%
    String filename = (String)request.getAttribute("filename");
    if (filename != null)
    %>
    <%= filename %>
    <%
    else
    %>
    it is null
    <%
    %>
    But the value is always null? Do I need any tag or declaration on the top of my JSP?

    Can i set attribute for list and get that list using request.getAttribute() in jsp?
    ex.
    in action
    List plist;
    plist = ...
    request.setAttribute("plist", plist);
    to get this value in jsp
    <%
    List plist = (List)request.getAttribute("plist");
    %>
    is this code is allowed?

  • How to retrieve checkboxes values?

    I am using a few checkboxes
    <form method="post" action="testgetPara.jsp">
    <input name="termcond1" type="checkbox" value="1" id="termcond" checked>
    <input name="termcond2" type="checkbox" value="2" id="termcond" >
    <input name="termcond3" type="checkbox" value="3" id="termcond" >
    <input type ="submit" name ="submit" value ="submit">
    </form>
    and hope to retrieve the "checked" values from these boxes
    so i do this
    <%int i = 0;
    //chkno is used only to retrieve the number of checked checkboxes
    String chkno[] = request.getParameterValues("chkdelbook");
                   //using a while loop to retrieve the value + execute it to the database.
    while (i < chkno.length)
    String isbn = request.getParameter("termcond");//get the specific array item
    out.println(isbn);
    //increment the i counter           
    ++i;
    %>
    but it doesn't seem to be working
    it return me with
    An error occurred between lines: 2 and 16 in the jsp file: /testgetPara.jsp
    Generated servlet error:
    C:\jakarta-tomcat-4.0.3\work\localhost\Testing\testgetPara$jsp.java:69: [] can only be applied to arrays. It can't be applied to java.lang.String.
         String isbn = request.getParameter("termcond")[i];//get the specific array item
         ^
    1 error
    this error
    may i know how to solve it?

    but it give me a java.lang.NullPointerException
    i have same id for my checkboxes, different name and
    values for them
    but it just doesnt work.NPE might be because tehere is no parameters named 'hobbies'
    having same ID is not same as having same NAME (see the difference ID vs NAME)
    if you had
    <form>
    <br>java<input type="checkbox" name="hobbies" value="java">
    <br>haskell<input type="checkbox" name="hobbies" value="haskell">
    <br>prolog<input type="checkbox" name="hobbies" value="prolog">
    <input type="submit">
    </form>
    and it would appear something like this:
    java [X]
    haskell[X]
    prolog[_]
    [submit]
    then you could probably write some code for it like this:
    String[] hobbies = request.getParameterValues("hobbies");
    for (int j = 0; j < hobbies.length; j++) {
    %>
    Your hobby is: <%= hobbies[j] %><br>
    <%
    }and it's output would hopefully look somewhat like this:
    Your hobby is: java
    Your hobby is: haskell
    of course i have not tryed that code nore looked methods up from API recently, so it might have some minor bugs.

Maybe you are looking for

  • [solved]xorg configuration issues, either no mouse or flickering

    Hey all, ok well a little while ago I was having trouble with hda-intel and trying to get a decent frame rate on my card, it was never solved, now after an upgrade the problem seems to have solved itself, that is except now it flickers when playing a

  • Connecting Yamaha keyboard with MIDI cable?

    So, I have a Yahama YPT-320 portable keyboard and would love to start recording some music through GarageBand. I know you need a MIDI cable, and I was wondering if this one works with iMac at GarageBand? The seller says that it works with Mac and PC,

  • Files not compatible with macbook pro

    i have difficulty opening files on my macbook pro, the senders of the files tell me to use windows as their files aren't compatible with apple. is there a way to convert files

  • Transaction handling in BPEL

    Hi, I have a BPEL process which invokes three different procedures. Each of these procedure performs some database updation. I want each of these procedure to be a part of same transaction. If execution of last procedure of the three, leads to rollba

  • How to Reduce Image Size and show upload Progress Bar

    i need to capture an image from the camera and send it to the server. however to reduce the amount of data transmitted i want to shrink the image and lower its resolution. I have code that currently does the following : UIImage *testImage = [UIImage