如何发布 JSTL 导入标记 () 的参数?

发布于 2024-07-23 06:58:57 字数 419 浏览 5 评论 0原文

我目前正在 JSP 页面中使用 JSTL 标记来导入外部页面的内容:

<c:import url="http://some.url.com/">
   <c:param name="Param1" value="<%= param1 %>" />
   ...
   <c:param name="LongParam1" value="<%= longParam1 %>" />
</c:import>

不幸的是,参数现在变得越来越长。 由于它们在 URL 中被编码为 GET 参数,因此我现在收到“414:请求 URL 太大”错误。 有没有办法将参数POST到外部URL? 也许使用不同的标签/标签库?

I'm currently using JSTL tag in a JSP page to import the content of an external page:

<c:import url="http://some.url.com/">
   <c:param name="Param1" value="<%= param1 %>" />
   ...
   <c:param name="LongParam1" value="<%= longParam1 %>" />
</c:import>

Unfortunately the parameters are now getting longer. Since they are encoded as GET parameters in the URL, I am now getting "414: Request-URL too Large" error. Is there a way to POST the parameters to the external URL? Maybe using a different tag / tag library?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小女人ら 2024-07-30 06:58:57

查看 http 后://www.docjar.com/html/api/org/apache/taglibs/standard/tag/common/core/ImportSupport.java.htmlhttp://www.docjar.com/html/api/org/apache /taglibs/standard/tag/el/core/ImportTag.java.html ,我得出的结论是,您无法使用 import 标记执行 POST 请求。

我想你唯一的选择就是使用自定义标签 - 编写一个 apache httpclient 标签应该很容易,它接受一些 POST 参数并输出响应文本。

After looking thru http://www.docjar.com/html/api/org/apache/taglibs/standard/tag/common/core/ImportSupport.java.html and http://www.docjar.com/html/api/org/apache/taglibs/standard/tag/el/core/ImportTag.java.html , i ve come to the conclusion that you cannot do a POST request using the import tag.

I guess the only choice you have is to use a custom tag - it should be pretty easy to write an apache httpclient tag that takes some POST param and output the response text.

‘画卷フ 2024-07-30 06:58:57

您需要一个 Servlet 以及 java.net.URLConnection 为此。

基本示例:

String url = "http://example.com";
String charset = "UTF-8";
String query = String.format("Param1=%s&LongParam1=%d", param1, longParam1);

URLConnection urlConnection = new URL(url).openConnection();
urlConnection.setUseCaches(false);
urlConnection.setDoOutput(true); // Triggers POST.
urlConnection.setRequestProperty("accept-charset", charset);
urlConnection.setRequestProperty("content-type", "application/x-www-form-urlencoded");

OutputStreamWriter writer = null;
try {
    writer = new OutputStreamWriter(urlConnection.getOutputStream(), charset);
    writer.write(query);
} finally {
    if (writer != null) try { writer.close(); } catch (IOException logOrIgnore) {}
}

InputStream result = urlConnection.getInputStream();
// Now do your thing with the result.
// Write it into a String and put as request attribute
// or maybe to OutputStream of response as being a Servlet behind `jsp:include`.

You'll need a Servlet with java.net.URLConnection for this.

Basic example:

String url = "http://example.com";
String charset = "UTF-8";
String query = String.format("Param1=%s&LongParam1=%d", param1, longParam1);

URLConnection urlConnection = new URL(url).openConnection();
urlConnection.setUseCaches(false);
urlConnection.setDoOutput(true); // Triggers POST.
urlConnection.setRequestProperty("accept-charset", charset);
urlConnection.setRequestProperty("content-type", "application/x-www-form-urlencoded");

OutputStreamWriter writer = null;
try {
    writer = new OutputStreamWriter(urlConnection.getOutputStream(), charset);
    writer.write(query);
} finally {
    if (writer != null) try { writer.close(); } catch (IOException logOrIgnore) {}
}

InputStream result = urlConnection.getInputStream();
// Now do your thing with the result.
// Write it into a String and put as request attribute
// or maybe to OutputStream of response as being a Servlet behind `jsp:include`.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文