Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Your site was well structured and I found what I was looking for in about 2 minutes. I am looking forward to participating with you in the future..."

Geography

Where in the world do Tek-Tips members come from?
blueindian1 (Programmer)
25 Apr 01 14:08
Hi,

Is it possible to assign a value to a JSP variable with a script?  I want to do something like the following:


<% String str = "jsp"; %>

<SCRIPT LANGUAGE="JavaScript">
<!--
if (document.all) {
  <%str = "modifed_by_the_script"; // assignment only when condition is met%>
  alert("Internet Explorer Detected");
}
// -->
</SCRIPT>


The way I have it, the string has a new value assigned regardless of whether the "if" condition is met

Thanks,

Rich
tiz (Programmer)
25 Apr 01 20:27
Nope, you can't really.

Can't think why you'd want to though? For browser detection, try:

<SCRIPT LANGUAGE="JavaScript">
<!--
n = (document.all) ? 0 : 1;
if (n) {
  alert("This is Netscape!");
} else {
  alert("This is IE!");
}
//-->
</SCRIPT>

The JSP engine ignores any conditional operators used in your JavaScript code so you can't embed any JSP scriptlets between the if statement for example. Take the following:
<% String str; %>
<script>
if (xyz) {
  <% str = "Test 1"; %>
} else {
  <% str = "Test 2"; %>
}
</script>

Will always set str to "Test 2" in your compiled JSP.

If you really need this kind of functionality, you may consider using Resin-JavaScript from Caucho.com - http://www.caucho.com/products/resin-js/.

Hope this helps,

Tim

--
Tim <tim@planetedge.co.uk>

blueindian1 (Programmer)
26 Apr 01 7:41
thanks!

the reason that i need to do it is because i need to know the browser type on the first page of my site after login. i can't use the login page to get it b/c the back end for the login process in a black box provided by i2, so i don't have access to that code.  i would like to get it it without having to post the first page immediatily after a user logs in ...but it looks like that is what i will have to do.
blueindian1 (Programmer)
26 Apr 01 7:43
one more thing...

i need to render different JSP depending on the browser...which is why I need for the JSP to know the browser...not just the Script.

:) thanks again
tiz (Programmer)
26 Apr 01 8:27
Well, you can get the browser type by simply parsing the string 'ua' in the following example:

<%

String ua = request.getHeader("user-agent");

out.println(ua);

%>


Based on whether 'ua' contains 'MSIE' or 'NAV' will tell you the browser type.

I suggest you use <jsp:forward> or <jsp:include> to display the appropriate HTML based on the browser type.

HTH,

Tim

--
Tim <tim@planetedge.co.uk>

blueindian1 (Programmer)
26 Apr 01 8:41
Tim,

You are the man!  I can't believe it's so easy....I've been looking forever!

Thanks,

Rich

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close