读书人

哪位高手给解决了 分就是哪位高手的

发布时间: 2012-01-30 21:15:58 作者: rapoo

谁给解决了 分就是谁的
我要实现的功能是:页面有几个复选框(checkbox),下面有个按纽,当我选中哪个的时候,点这个按纽,然后通过一个中间类,把页面选中的值保存到一个数组里,然后通过在另一个页面读这个数组,以达到显示的效果!

张飞


(按纽)

假如我选中了张飞和猪,然后点按纽,通过中间类(一些方法,如上我说的),然后跳到另一个页面显示!

张飞


急~我需要的是代码!
QQ:46430384
e-mail:zhufeilurui@126.com

[解决办法]
<input type= "checkbox " name= "chck " value= "张飞 "/> 张飞
<input type= "checkbox " name= "chck " value= "猪 "/> 猪
<input type= "checkbox " name= "chck " value= "毛 "/> 毛

<input type= "button " value= "保存 " onclick= "return doSelect(); "/>

<script language= "JavaScript ">
function doSelect(){
var checkedIds= " ";
var ChkEls=document.getElementsByName( "chck ");
for(var i=0;i <ChkEls.length;i++){
if(ChkEls[i].type != "checkbox ")continue;
if(ChkEls[i].checked)
checkedIds=checkedIds+ChkEls[i].value+ ", ";
}
if(checkedIds== " ")
alert( "请选择 ");
else
window.location.href= "xxx.do?checkedIds= "+checkedIds;
}
</script>

后台程序,直接将这个字符串传递到下一个页面。

下一个页面:
<%
String[] chcks=checkedIds.split( ", ");
for(int j=0;j <chcks.length;j++){
%>
<input type= "checkbox " name= "chck " value= " <%=chcks[j]%> "/> <%=chcks[j]%>
<%}%>

[解决办法]
晕啊,简单死了,根本用不着什么中间类,你把复选框名字设成一样的,直接用String[] args=request.getParameterValues( "riaio ");在另一个页面就能取到,
[解决办法]
<input type= "checkbox " name= "chck " value= "张飞 "/> 张飞
<input type= "checkbox " name= "chck " value= "猪 "/> 猪
<input type= "checkbox " name= "chck " value= "毛 "/> 毛

在中间类里
String [] chck=request.getParameterValues( "chck ");
StringBuffer chck1=new StringBuffer( " ");
for(int i=0;i <chck.length;i++){
if(i!=chck.length-1){
chck1.append(ccxm[i]+ "| ");
}else{
chck1.append(ccxm[i]);
}
}
request.setAttribute( "chck ",chck1.toString());
在显示页面里:
<%
String chck=(String)request.getAttribute( "chck ");
String [] chcks=chck.split( "| ");
for(int i=0;i <chcks.length;i++){
%>
<input type= "checkbox " name= "chck " value= " <%=chcks[j]%> "/> <%=chcks[j]%>
<%}%>

[解决办法]
汗,这么简单的功能都不愿自己写,还干什么程序员呀,回家种地去吧!!!
[解决办法]
再BS一下楼猪!
[解决办法]
用复选框取相同名就可以了 很简单的
[解决办法]
<h2> ======欢迎订购Sodi Pizza====== </h2>
<html:form action= "/order.do " method= "post " focus= " ">
<table border= "1 ">
<tr>
<td> 姓名 </td>
<td> <html:text property= "customerName "/> </td>


</tr>
<tr>
<td> 大小 </td>
<td>
<html:radio property= "size " value= "l "> 大 </html:radio>
<html:radio property= "size " value= "m "> 中 </html:radio>
<html:radio property= "size " value= "s "> 小 </html:radio>
</td>
</tr>
<tr>
<td> 盖头 </td>
<td>
<html:checkbox property= "topping(yc) " value= "洋葱 "/> 洋葱
<html:checkbox property= "topping(ydlxc) " value= "意大利香肠 "/> 意大利香肠
<html:checkbox property= "topping(nr) " value= "牛肉 "/> 牛肉
<html:checkbox property= "topping(j) " value= "姜 "/> 姜
<html:checkbox property= "topping(mt) " value= "面条 "/> 面条
</td>
</tr>
<tr>
<td> 送货方式 </td>
<td>
<html:select property= "type ">
<html:option value= "sendByShop "> 本店送货 </html:option>
<html:option value= "sendByCustomer "> 顾客自取 </html:option>
</html:select>
</td>
</tr>
<tr>
<td>
<html:submit value= "订购 "/>
</td>
<td>
<html:cancel value= "取消 "/>
</td>
</tr>
</table>
</html:form>
</center>

</body>

以上是第一个带复选的


public class OrderForm extends ActionForm
{
/*
* Generated fields
*/

/** type property */
private String type;

/** customerName property */
private String customerName;

/** size property */
private String size;

private Map topping = new HashMap();

/*
* Generated Methods
*/

public Map getTopping()
{
return topping;
}

public void setTopping(Map topping)
{
this.topping = topping;
}

/**
* Method validate
* @param mapping
* @param request
* @return ActionErrors
*/
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request)
{
// TODO Auto-generated method stub
return null;
}

/**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request)
{
// TODO Auto-generated method stub
}

/**
* Returns the type.
* @return String
*/
public String getType()
{
return type;
}

/**
* Set the type.
* @param type The type to set
*/
public void setType(String type)
{
this.type = type;
}

/**
* Returns the customerName.
* @return String
*/
public String getCustomerName()
{
return customerName;
}

/**
* Set the customerName.
* @param customerName The customerName to set
*/
public void setCustomerName(String customerName)
{
this.customerName = customerName;
}

/**
* Returns the size.


* @return String
*/
public String getSize()
{
return size;
}

/**
* Set the size.
* @param size The size to set
*/
public void setSize(String size)
{
this.size = size;
}
}

以上是formbean,接收数据


<body bgcolor= "pink ">
<center>
<h2> ======以下是您的订购信息====== </h2>
<html:form action= "/order.do " method= "post " focus= " ">
<table border= "1 ">
<tr>
<td> 姓名 </td>
<td> <bean:write name= "orderForm " property= "customerName "/> </td>
</tr>
<tr>
<td> 大小 </td>
<td>
<bean:write name= "orderForm " property= "size "/>
</td>
</tr>
<tr>
<td> 盖头 </td>
<td>
<%
OrderForm oform = (OrderForm)request.getAttribute( "orderForm ");
Map map = oform.getTopping();
Set keys = map.keySet();
Iterator it = keys.iterator();
StringBuffer sb = new StringBuffer();
while(it.hasNext())
{
String key = (String)it.next();
sb.append(map.get(key)+ " ");
}
out.print(sb.toString());
%>
<!--
<bean:write name= "orderForm " property= "topping "/>
-->
</td>
</tr>
<tr>
<td> 送货方式 </td>
<td>
<bean:write name= "orderForm " property= "type "/>
</td>
</tr>

</table>
</html:form>
</center>
显示确认页面

[解决办法]
给分呀,怎么解决了问题不给分啊

[解决办法]
一楼的方法,稍改一下.
--------------------------
下一个页面:
<%
String checkedIds = request.getParameter( "checkedIds ");//add this sentence
String[] chcks=checkedIds.split( ", ");
for(int j=0;j <chcks.length;j++){
%>
<input type= "checkbox " name= "chck " value= " <%=chcks[j]%> "/> <%=chcks[j]%>
<%}%>
[解决办法]
String[] list=(String[])parm.get( "name ");
for (int i = 0; i < list.length; i++) {

this.setName(list[i]);
}
------------------------
乱糟糟的,到最后还是设了最后一个值,有什么用.
[解决办法]
学习
[解决办法]
学习...
[解决办法]
把复选框名字设成一样的 复选框的name=riaio

action里直接用String[] args=request.getParameterValues( "riaio ");

读书人网 >Eclipse开发

热点推荐