当前位置:编程学习 > JAVA >>

struts2中action向jsp中传参问题

action向jsp传参总是拿不到,但是jsp传想action的值却能拿到
get set 方法自动添加没问题,求解决 --------------------编程问答-------------------- <s:property value="key"/> 或者 el 表达式 ${key} --------------------编程问答-------------------- 上代码,上报错信息,描述清楚,不然神也帮不了你! --------------------编程问答-------------------- 你是怎么取的 --------------------编程问答-------------------- 贴代码。。。 --------------------编程问答-------------------- 看代码才知道啊  速度上床代码! --------------------编程问答-------------------- 贴代码。。。 --------------------编程问答-------------------- 通过name属性取。。。 --------------------编程问答-------------------- 猜想 应该是重定向,,参数丢失。。 --------------------编程问答--------------------
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()
--------------------编程问答-------------------- 怎么不贴代码 --------------------编程问答-------------------- 放弃struts2吧。
stuts2根据你的resultType。将valuestack放在,request中。你可以使用struts标签取值。
也可以。但有些特殊情况你就没办法了,比如我现在的项目需要利用jsp输出一个树形结构。我是这样做的: --------------------编程问答--------------------
<%
    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) );
%>
--------------------编程问答-------------------- 这个是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=''这些就麻烦了,必须用插件 --------------------编程问答-------------------- 如果是用struts2做的,建议debug一下,可以看出值在什么位置,然后再取 --------------------编程问答-------------------- 请参考我的基于spring,security,struts的开源项目
http://blog.csdn.net/shadowsick
补充:Java ,  Java EE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,