Wednesday, 15 September 2010

javascript - check if request attribute is set with jQuery -



javascript - check if request attribute is set with jQuery -

is possible check if attribute nowadays in request object? have error cases error message has delivered client side:

servlet code:

request.setattribute("error", "the next term not found in index: " + terms); requestdispatcher dispatcher = request.getrequestdispatcher("graph.jsp"); dispatcher.forward(request, response);

i tried this, don't alert window @ all...

jsp code:

<script> var test = "${error}"; if(test != null) alert(test); </script>

if i'm reading right, have jsp app outputting javascript. in other words jsp page sets variable error string value. used generate javascript want alert contents of error variable.

your js code correct. couple things stand out me:

1) add together language attribute script tag (shown below)

<script language="javascript"> var test = "${error}"; if(test != null) alert(test); </script>

2) check errors in browser

i tested code have here , works me when error value akin "hello world". test variable gets set this. string not equal null (though empty string not equal null if statement's bit useless). makes me think perhaps string you're outputting ${error} may have double quote in it.

let's error is: next term not found in index: "avocado".

your generated js this:

<script language="javascript"> var test = "the next term not found in index: "avocado""; if(test != null) alert(test); </script>

note double quotes in double quoted string. syntax error.

if you're using chrome open developer tools (view > developer > console). reload page. see error message reported? if yes, what's error? if no, view source , @ generated js , post here scrutiny.

javascript jquery servlets

No comments:

Post a Comment