日期:2014-05-18  浏览次数:20783 次

高分悬赏答案-真的没人会吗?!!
我要实现的功能是:页面有几个复选框(checkbox),下面有个按纽,当我选中哪个的时候,点这个按纽,然后通过一个中间类,把页面选中的值保存到一个数组里,然后通过在另一个页面读这个数组,以达到显示的效果!

张飞


(按纽)

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

张飞


因为我用的是webwork框架,他的特点就是只要一个action,当接收数据的时候可以当作beanform用,输出的时候可以做为action,我的代码是这样写的,但是到页面上输出只输出true,还麻烦各位高手帮帮!
package   actioon;

import   java.util.*;
import   com.opensymphony.xwork.*;
import   com.opensymphony.webwork.*;
import   javax.servlet.http.*;

public   class   SaveAction   extends   ActionSupport{
private   String   name;



public   String   getName()   {
return   name;
}

public   void   setName(String   name)   {
this.name   =   name;
}

public   String   execute()   throws   Exception   {
try{
name();
}catch(Exception   ex){
return   ERROR;
}
return   SUCCESS;
}

public   void   name(){
ActionContext   ctx=ActionContext.getContext();      
HttpServletRequest   req=(HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
Map   parm   =   ctx.getParameters();
String[]   list=(String[])parm.get( "name ");
for   (int   i   =   0;   i   <   list.length;   i++)   {

this.setName(list[i]);
}

}

}
在线等!!

------解决方案--------------------
页面的复选框你附值没?张飞 <input type= "checkbox " name= "persons " value= "张飞 "> value不附值取出来就只显示on.
webwork没用过,直接用servlet和jsp写了个,点按扭提交给一个servlet,取出复选框值,直接放到request,然后转发到一个页面进行显示
String [] persons = request.getParameterValues( "persons ");
if (persons.length> 0){
request.setAttribute( "persons ",persons);
RequestDispatcher rd = request.getRequestDispatcher( "show.jsp ");
rd.forward(request,response);}
显示的时候String []persons = (String[])request.getAttribute( "persons ");
这样行不?

------解决方案--------------------
public String execute() throws Exception {
try{
name();
}catch(Exception ex){
return ERROR;
}
return SUCCESS;
}

这个方法应该还有其他形式的,,比如加几个参数的,HttpServletRequest,HttpServletRepsonse
这个很简单的,,保存到HttpSession 中,或则放到Reuqest中,到下个页面取就行了
------解决方案--------------------
request.getAttribute( "checkboxnm1 "),request.getAttribute( "checkboxnm2 "),组成一个数组,如果request.getAttribute( "checkboxnm1 "),request.getAttribute( "checkboxnm2 ")不为null,
则向数组里面添加...

------解决方案--------------------
补充一点:

如果用楼主的那个ACTION的话,NAME这个字段是不是该设置为数组?