简体   繁体   English

EL中的Spring webflow完整查询字符串

[英]Spring webflow full query string in EL

In short, how can I get the full query string using EL in a webflow view jsp? 简而言之,如何在webflow视图jsp中使用EL获取完整的查询字符串? This is what I am trying to do: 这就是我想要做的:

<span class="forgot-password">
  <a href="forgotPasswordRequest?<%=request.getQueryString() %>">
    <spring:message code="screen.welcome.link.forgotPassword" />
  </a>
</span>

Except I would like to use EL instead of the scriptlet <%=request.getQueryString() %> . 除了我想使用EL而不是scriptlet <%=request.getQueryString() %> It appears easy enough to get any individual parameter using ${param.someParameterName} , but I want the whole thing. 使用${param.someParameterName}获取任何单个参数似乎很容易,但我想要整个事情。 More specifically I am using CAS as an SSO provider. 更具体地说,我使用CAS作为SSO提供商。 In order to authenticate, an app would redirect its login to CAS with a query string containing the parameter service that is the URL to return to after successful authentication. 为了进行身份验证,应用程序会使用包含参数service的查询字符串将其登录名重定向到CAS,该参数service是成功进行身份验证后要返回的URL。 Something like this: 像这样的东西:

?service=http%3A%2F%2Fmysite.com%3A9080%2Fwelcome

My CAS login page has a link for a forgotten password webflow. 我的CAS登录页面有一个忘记密码webflow的链接。 I need to propagate that service parameter to that other webflow. 我需要将该服务参数传播到其他Web流。 So I could do something like this: 所以我可以这样做:

<span class="forgot-password">
  <a href="forgotPasswordRequest?service=${param.service}">
    <spring:message code="screen.welcome.link.forgotPassword" />
  </a>
</span>

But then I lose all the URL escaping. 但后来我失去了所有的网址转义。 Furthermore, if there are other parameters that I want to preserve in the future, they would be lost as well. 此外,如果将来还有其他要保留的参数,它们也会丢失。

The scriptlet currently works, but its ugly and I don't like having code (since this is true java code) in my presentation even though it is trivial. 这个小脚本目前有效,但它很难看,我不喜欢在我的演示文稿中使用代码(因为这是真正的java代码),尽管它很简单。 EL is certainly a much more elegant solution. EL肯定是一个更优雅的解决方案。

I poked around all of the Special EL variables listed in the spring documentation , but was still unable to come up with a way to get the full queryString. 我探讨了spring文档中列出的所有特殊EL变量 ,但仍无法找到获取完整queryString的方法。

-------------------------------- UPDATE -------------------------------- -------------------------------- UPDATE ----------------- ---------------

Ok, so I am making some ground... Turns out that the ExternalContext interface has a getNativeRequest() which is the actual HttpServletRequest object. 好吧,所以我正在制定一些基础......结果是ExternalContext接口有一个getNativeRequest() ,它是实际的HttpServletRequest对象。 From there I can get the full query string thusly: 从那里我可以得到完整的查询字符串:

externalContext.getNativeRequest().getQueryString()

So now I assume that since there is a Special EL variable called externalContext, i would just do this: 所以现在我假设因为有一个名为externalContext的特殊EL变量 ,我会这样做:

${externalContext.nativeRequest.queryString}

right? 对? Wrong! 错误! It turns out the externalContext variable is not available from the JSP page. 事实证明,JSP页面中没有提供externalContext变量。 Anyone know why? 谁知道为什么? However, there is also flowRequestScope , which is available to the JSP and has a getExternalContext method, so now I can do this: 但是,还有一个flowRequestScope ,它可用于JSP并具有getExternalContext方法,所以现在我可以这样做:

${flowRequestScope.externalContext.nativeRequest.queryString}

Cool, that works... But why is it necessary? 很酷,有效......但为什么有必要呢? Why are only some of the Special EL variables pushed to the JSP page, and why do some of them change ( viewScope seems to have all of its values promoted up a level to root so viewScope.commandName is referenced as ${commandName} in the JSP EL)? 为什么只有一些特殊EL变量被推送到JSP页面,为什么它们中的一些会发生变化( viewScope似乎将其所有值提升到了一个根级别,因此viewScope.commandName被引用为$ {commandName} JSP EL)? I must be missing something fundamental in the way WebFlow works. 我必须错过WebFlow工作方式的基本内容。 Can someone point me in the right direction? 有人能指出我正确的方向吗?

In webflow, essentially the scope map is for ease of differentiation for your controlling logic on the server. 在webflow中,范围映射主要是为了便于区分服务器上的控制逻辑。 In straight up Spring MVC, that would be your controllers, but in webflow your flow more or less serves this purpose directly. 在直接的Spring MVC中,这将是您的控制器,但在webflow中,您的流程或多或少直接用于此目的。 Virtually everything you put in your scope map is rolled up into the request attributes for use on the JSP, except for request scope which is explicitly destroyed when the flow returns. 实际上,您在范围映射中放入的所有内容都会汇总到请求属性中以供JSP使用,但在流返回时显式销毁的请求范围除外。 That's why viewScope.commandName is available in the JSP - because it, like the other scopes, are rolled up into a large request attribute map which is then placed into the request for your JSPs to access. 这就是为什么viewScope.commandName在JSP中可用 - 因为它与其他作用域一样,被汇总到一个大的请求属性映射中,然后将其放入JSP访问的请求中。

The difference is that the lower-lived scopes are used first. 不同之处在于首先使用寿命较低的范围。 Lower scopes always take precedence over longer-lived scopes, just like local variables in Java taking precedence over class-level variables of the same name. 较低的范围始终优先于较长寿的范围,就像Java中的局部变量优先于同名的类级变量一样。 So you need to make sure to use unique parameter names just in case so there is no chance of collision. 因此,您需要确保使用唯一的参数名称以防万一,因此不会发生冲突。

If you really needed that value, it would be easiest to, in the flow, use a set tag to set that value in an appropriate scope so that you had it named easier, such as 如果你确实需要这个值,那么在流程中使用set标签在适当的范围内设置该值是最容易的,这样你就可以更容易地命名它,比如

<set name="viewScope.currentService" value="externalContext.nativeRequest.queryString" />

That way you have the EL variable "currentService" available in your view scope. 这样,您可以在视图范围中使用EL变量“currentService”。 You may want to use on-render or on-entry to store this value into your view. 您可能希望使用on-render或on-entry将此值存储到视图中。 For this particular value, I'd probably use on-render since it's something that may be change based on how the view is rendered, but it might not matter either way. 对于这个特定的值,我可能会使用on-render,因为它可能会根据视图的呈现方式而改变,但它可能无关紧要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM