action向jsp传参总是拿不到,但是jsp传想action的值却能拿到
get set 方法自动添加没问题,求解决

解决方案 »

  1.   

    <s:property value="key"/> 或者 el 表达式 ${key}
      

  2.   


    get set 方法是要有,但一定要对应页面上的元素 name 属性 。<form action="test.action" method="post">
         <input type="text" name="username"/>
         <input type="submit" value="submit"/>
    </form>
    action 里的 set get 方法为:
    setUsername(String username),getUsername()
      

  3.   

    放弃struts2吧。
    stuts2根据你的resultType。将valuestack放在,request中。你可以使用struts标签取值。
    也可以。但有些特殊情况你就没办法了,比如我现在的项目需要利用jsp输出一个树形结构。我是这样做的:
      

  4.   

    <%
        ValueStack stack = (ValueStack) request.getAttribute("struts.valueStack");
        Department root = (Department) stack.findValue("root");
        Department show_depa = (Department) stack.findValue("showDepa");    List<Department> depa_list = new LinkedList<Department>();
        depa_list.add( root );    String context_path = application.getAttribute("context_path").toString();
        out.print( treeUL(  depa_list ,context_path,show_depa) );
    %>
      

  5.   

    这个是struts2放入值的源码。
      */
        public void serviceAction(HttpServletRequest request, HttpServletResponse response, ServletContext context,
                                  ActionMapping mapping) throws ServletException {        Map<String, Object> extraContext = createContextMap(request, response, mapping, context);        // If there was a previous value stack, then create a new copy and pass it in to be used by the new Action
            ValueStack stack = (ValueStack) request.getAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY);
            boolean nullStack = stack == null;
            if (nullStack) {
                ActionContext ctx = ActionContext.getContext();
                if (ctx != null) {
                    stack = ctx.getValueStack();
                }
            }
            if (stack != null) {
                extraContext.put(ActionContext.VALUE_STACK, valueStackFactory.createValueStack(stack));
            }        String timerKey = "Handling request from Dispatcher";
            try {
                UtilTimerStack.push(timerKey);
                String namespace = mapping.getNamespace();
                String name = mapping.getName();
                String method = mapping.getMethod();            Configuration config = configurationManager.getConfiguration();
                ActionProxy proxy = config.getContainer().getInstance(ActionProxyFactory.class).createActionProxy(
                        namespace, name, method, extraContext, true, false);            request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, proxy.getInvocation().getStack());
                // if the ActionMapping says to go straight to a result, do it!
                if (mapping.getResult() != null) {
                    Result result = mapping.getResult();
                    result.execute(proxy.getInvocation());
                } else {
                    proxy.execute();
                }
    你想要jdb后台打印你的值。不好弄,简单的字符串可以。但像这些 filed[0].id="" filed[1].name=''这些就麻烦了,必须用插件
      

  6.   

    如果是用struts2做的,建议debug一下,可以看出值在什么位置,然后再取
      

  7.   

    请参考我的基于spring,security,struts的开源项目
    http://blog.csdn.net/shadowsick