• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

JSP: How would I do this?

kukyfrope

Senior member
As my last post, I'm used to PHP and done hardly any Java/JSP, so please forgive my ignorance.

I'm wanting to check if a GET parameter exists, and assign that value to a string if it does or doesn't. Basically I want it so that the following actions happen:

page.jsp?t=helloworld
String myvariable = "helloworld";

page.jsp
String myvariable = null;

I thought the below code would work, but apparently the syntax is wrong in someway. Does the if() condition I'm using check if the param exists? Or is the error occurring because the t param doesn't exists, and it has no value to compare it against? Can somebody fix this? Thanks!
 
I'm not a Javascript expert, but isn't that block equivalent to just saying:

String servicetype = request.getParameter("t"); ?

If the return value is null, you make servicetype null, and otherwise you make it equal to the return value.

If you're getting syntax errors, I'd check what getParameter returns when the variable you are asking about is undefined.

Also, there could be scope issues, since you're sort of 'defining' the variable twice (and both times within a block). Try:

 
Back
Top