如何防止在URL中显示空的GET变量 [英] How do I prevent empty GET variables from displaying in the URL
问题描述
/ GetResults?title = hello& year =&导演=& firstname =& lastname =
这是正常还是我做错了什么?这里是我使用的表单:
< form action =/ FabFlix / servlet / GetResultsid =search- formmethod =getaccept-charset =utf-8>
< p>电影标题:< / p>< input type =textname =title/>
< br />
< p>年份:< / p>< input type =textname =year/>
< br />
< p>导演:< / p>< input type =textname =director/>
< br />
< p> Star的名字:< / p>< input type =textname =firstname/>
< br />
< p> Star's Last Name:< / p>< input type =textname =lastname/>
< br />
< br />
< input type =submit/>
< / form>
这很正常。为了防止这种行为,请考虑在表单上手动组装URL并重定向的onsubmit处理程序。如果你这样做,不要忘记测试这与JavaScript启用和禁用,以确保两种情况下仍然工作正常。
I'm having a bit of a weird situation here. I have a form that submits using the GET method for a search function. On the subsequent page after a search, all the variables are displayed in the URL even if they are empty. For example if I make a search for movie title equaling "hello," I'll get this:
/GetResults?title=hello&year=&director=&firstname=&lastname=
Is this normal or am I doing something wrong? Here is the form I am using:
<form action="/FabFlix/servlet/GetResults" id="search-form" method="get" accept-charset="utf-8">
<p>Movie Title:</p><input type="text" name="title"/>
<br/>
<p>Year:</p><input type="text" name="year"/>
<br/>
<p>Director:</p><input type="text" name="director"/>
<br/>
<p>Star's First Name:</p><input type="text" name="firstname"/>
<br/>
<p>Star's Last Name:</p><input type="text" name="lastname"/>
<br/>
<br/>
<input type="submit"/>
</form>
This is normal. To prevent this behavior, consider an onsubmit handler on your form which assembles the URL manually and redirects. If you do this, don't forget to test this with javascript both enabled and disabled to make sure both scenarios still work OK.
这篇关于如何防止在URL中显示空的GET变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!