views:

13

answers:

1

I am editing other people's code, written in server-side JS for ASP, and have run into a problem that probably has a very simple solution.

I'm outputting some code from a URL param like this:

<%=Request.QueryString("param")%>

The problem is that if the param doesn't exist, I need to do something else. So I tried:

<% 
  var param = Request.QueryString("param");
  if (!param) { param = "Some Default Value"; }
%>
<%=param%>

The problem is that the if never seems to evaluate to true, even when the URL param is missing. I'm guessing that the !image condition doesn't work here. What should my test condition be?

(Please forgo stern warnings about doing escaping of URL params to prevent XSS.)

A: 

In JSP you have to use getParameter instead of QueryString

The code in JSP would be

<% 
  String param = request.getParameter("param");
  if (param.length() == 0) { param = "Some Default Value"; }
%>
Luka
I'm not using JSP. This is for an ASP site with pages written in Javascript instead of VBScript.
levik