开发者

how to store querystring value in variable

I am getting the value from error.jsp to staff.jsp page.

Welcome to <%= (String)request.getParameter("facilityname")%>

I have a form in staff.jsp page. When the user enter invalid username or password staff.jsp page refreshes and shows err开发者_高级运维or, now at the top of page where I am getting the clinic name getting

null value and my page becomes like

Welcome to null.

How can i solve this please?


Without more of the code (markup for the form, for instance), it's hard to say, but:

If "facilityname" really is the name of a field in the form being submitted, then you should be getting that field's value from getParameter and so that code should work (although it will fail if the page is refreshed without a form being submitted). Did you use an id rather than a name on the field? Is the capitalization correct?

If you want the page to work properly regardless of whether the form was submitted:

<%
String facilityname;

facilityname = (String)request.getParameter("facilityname");
if (facilityname != null && facilityname.length > 0) {
    out.print("Welcome to " + facilityname + ".");
}
%>

Of course, that (like your original) is inviting someone to inject HTML markup on up your page, since it doesn't escape any HTML characters in the input. You definitely need to do that with one of the several utility classes available (various ways recommended in this other question on SO).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜