开发者

using request.getParameter()

开发者 https://www.devze.com 2023-03-02 07:15 出处:网络
i\'ve a login page when you successfuly login by entering username and password you are directed to home.jsp

i've a login page when you successfuly login by entering username and password you are directed to home.jsp on home.jsp..i've used request.getParameter() for both id and passwd,which checks and then only let it enters..

but wh开发者_开发技巧en i'm usind a simple href html link for home..it always shows me nullexception as id and password is not there and request.getParameter() shows error..


but when i'm usind a simple href html link for home..it always shows me nullexception as id and password is not there and request.getParameter() shows error..

It is because your request doesn't hold username password when you make simple GET using a href.

Passing username & password in URL isn't good. Why don't you use Session to hold current logged user's data.


If your tag looks like

<a href="turnip.jsp">click me</a>

`

then indeed, you aren't passing the parameters

It needs to look like

<a href="turnip.jsp?id=me&password=mysecret">click me</a>

NOTE: As pointed out by others, there are many security reasons why this kind of structure should be used with care.


If you use a <a href=""/> like you specified it, the HTML form content containing username and password will not be submitted. It will create a HTTP GET request and not send any form parameters.

If you use a 'submit' button, it will create a HTTP POST request and send the form parameters to the server.

If you want to keep the link as <a href=""/> then you can add an 'onclick' javascript to your href and call a submit() on your form.

0

精彩评论

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