web頁面回傳checkbox的問題

2021-04-06 18:11:54 字數 2416 閱讀 1086

問題原型:

新增頁面中有10個checkbox,使用者選中了5個後提交

修改頁面中應顯示10個checkbox,同時應該有5個已經被選中

詳細實際問題:

為了滿足業務需要,從linux安裝盤中的comps.xml中讀取提供的服務所依賴的包

顯示在頁面上,根據包的型別(default,mandatory,optional)決定顯示的方法

default預設選中,mandatory不提供選擇,optional為使用者可選

<

c:choose

>

<

c:when 

test

="$"

>

<

td>

<

input 

type

="checkbox"

name

="noderpms"

style

="visibility: hidden; "

checked

="true"

value

="$"

/>

"/>

td>

c:when

>

<

c:when 

test

="$"

>

<

td>

<

input 

type

="checkbox"

name

="noderpms"

checked

=true  

value

="$"

/>

"/>

td>

c:when

>

<

c:when 

test

="$"

>

<

td>

<

input 

type

="checkbox"

name

="noderpms"

value

="$"

/>

"/>

td>

c:when

>

c:choose

>

在處理層,採用struts的form來接受,定義string noderpms接受即可

接受後存在資料庫裡,然後讀出來在顯示在頁面上

在修改頁面,首先應該有全部的checkbox,同時使用者選中的應該已經被打勾(這來自資料庫讀出的記錄),經過中午的查詢資料

才知道可以使用mutilbox解決這個問題

<

c:choose

>

<

c:when test="

$"

>

<

td>

<

input type="

checkbox

"name="

noderpms

"style="

visibility: hidden; 

"checked="

true

"value="

"$

"/>

"/>

td>

c:when

>

<

c:otherwise

>

<

td>

<

html:multibox property="

noderpms

">

<

c:out

value="

$"

/>

html:multibox

>

td>

c:otherwise

>

c:choose

>

mutilbox會根據你讀出的值來設定

struts中的checkbox是單選的,它的值應該只有true和false或者yes no或者on off之分;

r如果希望使用一組可以多選的checkbox,在struts中的頁面標籤應該是html:multibox,它的用法:或者

value2

真正載頁面上使用時可能是這樣:ab

c當然"strarray"一定是頁面相對應的formbean中的乙個屬性,並且應該是陣列:

private string strarray; //提供get set方法

這樣,如果我們在頁面上面選中了前兩個,則strarray.length=2;strarray[0]裡面的值是a,strarray[1]裡面的值是b;

如果我們把form中的strarray設定為strarray[0]="b",strarray[1]="c",則轉到頁面之後,頁面上只有後兩項被選中

所以這樣就可以解決問題了

頁面回發和事件回傳

客戶端 瀏覽器 客戶端事件 傳送資料 資料 服務端 引發伺服器端事件處理程式 處理資料 處理完畢,重新形成 html 傳送 html 客戶端 瀏覽器 展示 頁面回發包含了 頁面第一次傳送到客戶端引起的 not ispostback 和客戶端事件 事件回傳 引起的頁面回發 上面的圖就是頁面回發的示意圖...

Android頁面之間進行資料回傳

要求 頁面1跳轉到頁面2,頁面2再返回頁面1同時返回資料 頁面1新增如下 intent intent new intent intent.setclass 頁面1.this,頁面2.class bundle bundle new bundle intent.putextras bundle 將bun...

回傳後保持頁面的滾動位置

預設情況下,asp.net頁面回傳到伺服器後,頁面會跳回頂部。對於乙個內容較多的頁面,你或許有需要自動滾動到使用者最後操作的位置。頁面屬性 maintainscrollpositiononpostback 可以解決這樣的問題,有以下3種方法。應用程式級 作用物件 的所有asp.net頁面 方法 開啟...