【问题标题】:how do i call the action name from the web.xml instead of typing the action name at the url of the browser如何从 web.xml 调用操作名称,而不是在浏览器的 url 中键入操作名称
【发布时间】:2011-03-18 08:04:48
【问题描述】:

在我的 struts2 应用程序中,我有一个类似这样的 struts2 标签复选框列表

 <s:checkboxlist name="yourSelect" label="Are You Inteterested In"    
       list="communityList" value="defaultSelect" /> 

我在我的动作类构造函数中添加了列表元素

查看纯副本到剪贴板打印?

 public CustomerAction()  
      {  
         communityList = new ArrayList<String>();  
            communityList.add("WebSpere Consultuing");  
          communityList.add("Portal Consulting");  
          communityList.add("SOA/BPM Consulting");  
            communityList.add("Content Management");  
    }  

public CustomerAction() { communityList = new ArrayList(); communityList.add("WebSpere 咨询"); communityList.add("门户咨询"); communityList.add("SOA/BPM 咨询"); communityList.add("内容管理"); }

而且我可以很好的显示在jsp页面上,

但问题是当我在 web.xml 中调用 jsp 页面时

<welcome-file-list>
<welcome-file>/pages/Customer.jsp</welcome-file>
</welcome-file-list>

列表未填充,当我从其构造函数具有列表值的类的 struts.xml 请求操作名称时,列表正在填充​​p>

如何将 web.xml 中的操作名称作为欢迎列表文件调用,而不是在 url 中键入操作名称.....

【问题讨论】:

    标签: struts2


    【解决方案1】:

    您可以在其&lt;head&gt; 中创建一个新的欢迎 jsp 或 html 文件:

    <meta http-equiv="Refresh" CONTENT="0; URL = /project/MyAction.action"/>
    

    这将调用您的 Struts2 操作,该操作将处理填充 ArrayList 并将您转发到您真正的欢迎页面。

    This thread 有一些其他的提示也可能有用。

    【讨论】:

    • 您好,感谢您的回答,它工作正常,现在我可以调用 url 中的动作类来加载复选框列表值,但是如果我调用动作类来呈现 jsp 页面,则会显示与验证。实际上,验证应该在我按下页面中的提交按钮后出现。不是在输入时间。那么我该如何解决这个问题?
    • 您可以在您的操作类中创建一个名称类似于 prep() 的方法,该方法负责呈现 jsp,然后将 prep() 从您的验证中排除。 excludeMethod 参数在拦截器堆栈定义中执行此操作:struts.apache.org/2.x/docs/…
    【解决方案2】:

    创建一个带有重定向的简单 JSP。

    <% response.sendRedirect("myaction.action"); %>
    

    【讨论】:

      猜你喜欢
      • 2015-10-07
      • 2015-12-07
      • 1970-01-01
      • 2015-05-10
      • 1970-01-01
      • 2014-03-06
      • 1970-01-01
      • 2013-07-22
      • 2013-12-04
      相关资源
      最近更新 更多