0

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 error, 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?

RB.
  • 36,301
  • 12
  • 91
  • 131
Learner
  • 335
  • 2
  • 7
  • 16

1 Answers1

1

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).

Community
  • 1
  • 1
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • Welcome to <%= (String)request.getParameter("facilityname")%> I am getting parameter outside the form. This parameter only shows clinic name. This parameter have nothing to do with form. Problem is when staff.jsp refreshes i get the null value in facility name. – Learner Apr 05 '11 at 09:54
  • @Bilal: You'll have to explain more thoroughly what you're doing and where control is getting passed from page to page. *In general*, since a query string parameter is specific to a request (it's part of the `GET`), it won't get magically preserved moving from page to page, you have to ensure that it's in the page's URL (on the `form` `action`, for instance). – T.J. Crowder Apr 05 '11 at 10:01
  • @Bilal: Good deal, glad that was of some help! – T.J. Crowder Apr 05 '11 at 11:31