JSP: Utilisation d’un Checkbox dans un formaulaire jsp

Author:
//File: index.html
<HTML>
<!--
  Copyright 2004 The Apache Software Foundation
 
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
 
      http://www.apache.org/licenses/LICENSE-2.0
 
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
 
<BODYbgcolor="white">
 
 
<FORMTYPE=POST ACTION=checkresult.jsp>
<BR>
<fontsize=5 color="red">
Check all Favorite fruits: <br>
 
<inputTYPE=checkbox name=fruit VALUE=apples> Apples <BR>
<inputTYPE=checkbox name=fruit VALUE=grapes> Grapes <BR>
<inputTYPE=checkbox name=fruit VALUE=oranges> Oranges <BR>
<inputTYPE=checkbox name=fruit VALUE=melons> Melons <BR>
 
 
<br> <INPUTTYPE=submit name=submit Value="Submit">
 
</font>
</FORM>
</BODY>
</HTML>
 
//////////////////////////////////////////////////////////////
 
 
//File: checkresult.jsp
<html>
<!--
  Copyright 2004 The Apache Software Foundation
 
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
 
      http://www.apache.org/licenses/LICENSE-2.0
 
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
 
<bodybgcolor="white">
<fontsize=5 color="red">
<%! String[] fruits; %>
<jsp:useBeanid="foo" scope="page" class="checkbox.CheckTest" />
 
<jsp:setPropertyname="foo" property="fruit" param="fruit" />
<hr>
The checked fruits (got using request) are: <br>
<% 
  fruits = request.getParameterValues("fruit");
%>
<ul>
<%
    if (fruits != null) {
    for (int i = 0; i < fruits.length; i++) {
%>
<li>
<%
        out.println (util.HTMLFilter.filter(fruits[i]));
    }
  } else out.println ("none selected");
%>
</ul>
<br>
<hr>
 
The checked fruits (got using beans) are <br>
 
<% 
    fruits = foo.getFruit();
%>
<ul>
<%
    if (!fruits[0].equals("1")) {
    for (int i = 0; i < fruits.length; i++) {
%>
<li>
<%
      out.println (util.HTMLFilter.filter(fruits[i]));
    }
  } else out.println ("none selected");
%>
</ul>
</font>
</body>
</html>
 
 
 
           
       

Cet article JSP: Utilisation d’un Checkbox dans un formaulaire jsp est apparu en premier sur .