【问题标题】:Passing Value in Struts 2 from JSP to JSP将 Struts 2 中的值从 JSP 传递到 JSP
【发布时间】:2012-06-04 09:46:51
【问题描述】:

我在一个 JSP 页面中有下面的代码。

<s:url value="/user/search.jsp" >
    <s:param name="profile.gender" value="profile.gender"></s:param>
</s:url>

它完美地链接到 /user/search.jsp 并且 profile.gender 的值显示在浏览器的地址栏中(一个查询字符串)。在我的 /user/search.jsp 中,如何在文本字段中访问和显示 profile.gender 的值?

<s:textfield value="?"/>

【问题讨论】:

  • 我不确定 search.jsp 是否是另一个页面?您是否尝试在不使用任何 Action 类的情况下从另一个 jsp 调用?
  • 是的,search.jsp 是另一个页面。
  • 我不知道你为什么要这样做,因为你违反了 MVC2 的基本原则。从一个 JSP 到另一个 JSP 的每个请求都应该通过一个 Action。

标签: jsp struts2


【解决方案1】:

正如已经建议的那样,不要从 jsp 转移到 jsp 而是通过操作

<s:url value="myaction.action" >
    <s:param name="gender" value="profile.gender"></s:param>
</s:url>

@Result(name="success", value="/search.jsp") // If you prefer annotation or configure in xml
public class MyAction extends ActionSupport {
  private String gender = null;
  //getter setter here    
  public String execute(){
    return Action.SUCCESS;
  }
}

search.jsp

<s:textfield value="gender"/>

【讨论】:

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