使用jstl解析字符串变量
这是我的问题。
我需要设置一个流程,最好使用 jstl/jsp,根据客户端在 URL 参数中输入的内容,将返回某个 URL,并传递相同的参数,并通过 javascript 弹出函数打开。
我遇到的问题是,选择语句找不到参数之一,除非它是起始参数之一。 (现在你的想法是,“嗯?”)
客户端传递的参数列表看起来像这样......
?name=personsname&email=personsemail&tmplatecde=7&legalid=20266998&photoURL=%2Favmedia%2Fweb%2Findex%2F25505893822%2EJPG&agentNumber=047666&FWSType=FR&des=,+CLU%AE,+ChFC%AE&postto=thenetwork.nmfn.com&agentnumber=047666&formname=FWSContactForm2&attr=FRSite
在该参数中,我只需要“formname”。但是,如果我像这样放入查询字符串(这是客户端所期望的),它将找不到表单名称。将 formname 参数移动到 'name' 参数之前,它可以工作。
在我的公司,我们构建了一个自定义 JSP 标记,它可以简单地获取该查询字符串并将其附加到指定的 URL,但为了确定该 URL,我还需要检查表单名称是否相等。
有谁知道解析字符串以获取 formname 值的适当方法吗?
到目前为止,我拥有的与此问题相关的代码是
<c:choose><c:when test='${param.formname == "FWSContactForm2"}' >
任何帮助将不胜感激。
Here's my problem.
I need to set up a process, preferably with jstl/jsp, that depending on what a client enters in a URL parameter, a certain URL will be returned, with the same parameters passed on, and opened via javascript pop up function.
Problem I am having, is that the choose statement is not finding one of the parameters unless its one of the beginning parameters. (Now your thinking, 'huh?')
The list of parameters the client is passing, looks like this...
?name=personsname&email=personsemail&tmplatecde=7&legalid=20266998&photoURL=%2Favmedia%2Fweb%2Findex%2F25505893822%2EJPG&agentNumber=047666&FWSType=FR&des=,+CLU%AE,+ChFC%AE&postto=thenetwork.nmfn.com&agentnumber=047666&formname=FWSContactForm2&attr=FRSite
Out of that parameter, I only really need the 'formname.' However if I put the query string in like that, which is what the client is expecting to do, it won't find the formname. Move the formname parameter to before the 'name' parameter, it works.
At my company we built a custom JSP tag that can simply take that query string and attach it to a specified URL, but to determine that URL I need to check what the formname is equal too.
Does anyone have any ideas of an appropriate way to parse the string to get that formname value?
So far, the code that I have that matters to this issue is
<c:choose><c:when test='${param.formname == "FWSContactForm2"}' >
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它应该工作正常。然而,该查询字符串包含一个特殊字符,该字符使用 ISO-8859-1 进行 URL 编码,即
%AE
(注册商标 ®)。也许 servlet 容器正在使用错误的字符集对其进行解码,并且一个失败接一个失败。删除该%AE
部分并重新测试。如果它有效,我会调查相关 servlet 容器的 URL 编码配置。另一方面,如果您可以完全控制应该发送此查询字符串的页面,您还可以将响应字符集设置为与 servlet 容器正在使用的字符集相同。这样会破坏更少的东西。It should work fine. That query string however contains a special character which is been URL-encoded using ISO-8859-1, the
%AE
(the registered mark ®). Maybe the servletcontainer is decoding it using the wrong charset and the one failure followed the other. Remove that%AE
part and retest. If it works, I'd investigate the URL encoding configuration of the servletcontainer in question. On the other hand, if you have full control over the page which is supposed to send this query string, you could also set the response charset to the same as what the servletcontainer is using. That would break less things.