开发者

Passing a url in a form from page to servlet drops part of query string

开发者 https://www.devze.com 2023-04-09 19:38 出处:网络
If I have a form on a JSP like this: <form action = \"/myApp/myServlet?rssFeedURL=${rssFeedURL}\' />\" method = \"post\">

If I have a form on a JSP like this:

<form action = "/myApp/myServlet?rssFeedURL=${rssFeedURL}' />" method = "post">
    <input type = "button" value = "See data for this RSS feed."/>
</form>   
开发者_运维百科

What I find is that if the variable ${rssFeedURL} has no query string, then the server receives it properly, e.g.:

http://feeds.bbci.co.uk/news/rss.xml

But if a query string exists, e.g.:

http://news.google.com/news?ned=us&topic=m&output=rss  

I expect that it is to do with the encoding of the '&' character. Can anyone advise?

The server receives only:

http://news.google.com/news?ned=us

My pages are charset=UTF-8 encoded.


You need to URL-encode request parameters. Otherwise they will be interpreted as part of the initial request URL.

JSTL offers you the <c:url> for this.

<c:url var="formActionURL" value="/myApp/myServlet">
    <c:param name="rssFeedURL" value="${rssFeedURL}" />
</c:url>

<form action= "${formActionURL}" method="post">
    ...

An alternative is to create an EL function which delegates to URLEncoder#encode().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号