By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,474 Members | 1,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,474 IT Pros & Developers. It's quick & easy.

Accessing the request attribute in the onLoad() event.

P: n/a
Hi,
I have cr8ed a javascript function in the head section of a jsp
page.

<!--
function go(theURL) {

alert(theURL);

if (theURL!=null){

window.open(theURL,'popup','scrollbars=yes,resizab le=yes,width=800,h

eight=600');
}
}
//-->

This function receives a url and displays it in the pop up window.
This function is called by the onLoadevent() during the loading of the
page. The parameter passed is obtained using the request attribute in
the foll. manner.

<body text="#003366" onLoad="javascript:go(
<%request.getParameter("val");%>)" >

The alert() function in the javascript method display "unspecified"
message in this example.
However, accessing the request attribute and storing it in a string
gives me the required result.
ie. String url = <%request.getParameter("val");%> gets the correct
url.

Just want to know if it is possible to use the request attribute
during the onLoad() event.

cheers



String name=request.getParameter("val");

<a href="javascript:go('<%=url %>')">Click to view</a>

<jsp:forward page = "centre1.jsp">

<jsp:param name = "val" value="<%= url %>"/>

</jsp:forward>

<%/*response.sendRedirect("centre1.jsp");*/%>
Jul 23 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
On 30 Sep 2004 03:58:43 -0700, Sunny <su************@hotmail.com> wrote:
I have cr8ed
Is it really that difficult to type 'eat' instead of '8'?

[snip]
<!--
It's not necessary to hide scripts from browsers any more. Remove the
comment delimiters.

[snip] The parameter passed is obtained using the request attribute in
the foll. manner.
Wow! You've now saved a whopping six characters from your abbreviations.

Please write in full.
<body text="#003366" onLoad="javascript:go(
<%request.getParameter("val");%>)" >
The 'javascript:' prefix isn't needed. It's just a label in all but one
browser, and it doesn't matter even in that case most of the time. Remove
it.

[snip]
Just want to know if it is possible to use the request attribute
during the onLoad() event.


You seem to be confused as to what happens when. You don't use request in
a load event. By the time the client sees the page, the server has
substituted the code for a value of some kind, and that is what's used.

This is why showing server-side code is useless. It doesn't actually show
the problem because it has no bearing on client-side execution. It's the
values that *result* from the server-side code that matter.

I suspect that the problem is simply an unquoted value. I haven't used
JSP, but I assume that the code above returns an unquoted string, correct?
If so, just place a single quote before the <% and another after the %>.
If that doesn't help, post what you get when you view the source in the
browser.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2

P: n/a
Hi,

In article <opse428pr2x13kvk@atlantis>, Michael Winter wrote:
On 30 Sep 2004 03:58:43 -0700, Sunny <su************@hotmail.com> wrote:

<!--


It's not necessary to hide scripts from browsers any more. Remove the
comment delimiters.


It's useful though, since some site-search engines are prevented to index
script blocks through this. A good example is PHPdig.

Ranbir
Jul 23 '05 #3

P: n/a
On Thu, 30 Sep 2004 14:27:37 +0200, Ranbir Kaur <sm****@yahoo.com> wrote:

[snip]
It's not necessary to hide scripts from browsers any more. Remove the
comment delimiters.


It's useful though, since some site-search engines are prevented to
index script blocks through this. A good example is PHPdig.


In that case, do what you probably should be doing, anyway. Move the
script into an external file.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #4

P: n/a
Sunny wrote:
This function receives a url and displays it in the pop up window.
No, that may be what you intend it to do. However, in a lot of browsers it won't do
anything except possibly warn the user a Web page tried to open a new window and the
attempt was captured and suppressed. This list of browsers includes, but isn't
limited to:

IE < 6.0.2900 with the google toolbar, the newest AIM w/popup blocker installed or
any other popup blocker (Window Washer, some Symantec software, Proxomitron, etc)
IE 6.0.2900 in it's default configuration
Any Gecko-based browser (Mozilla, Netscape, Firefox, Camino) in it's default
configuration
Opera 7.54 if configured to "Block unwanted pop-ups" (I haven't bothered to check,
but I'd bet it will start coming configured that way in 7.6)

All these browsers and browser add-ons come with this option because people are sick
of new windows popping up simple because they chose to visit a Web site.

Of course, if this is for an Intranet application, and you control the browsers
used, and their configuration, then by all means continue to open a new window on
page load.
Just want to know if it is possible to use the request attribute
during the onLoad() event.


Sure you can use a server-side request in an onload event:

<% String val = request.getParameter("val"); %>
<body onload="alert('<%= val %>');">

As some others have said, it's most likely that you didn't quote the string that
gets returned from request.getParameter(). In other words, you're doing this:

<% String val = request.getParameter("val"); %>
<body onload="alert(<%= val %>);">

(note the missing inner single quotation marks on the call to alert())

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #5

P: n/a
Sorry, but at the end of the day, typing full words (when one can do
with abbreviations and get the message across)is the last thing on my
mind. hehehehehe!!!!

Aneways, When i use <body text="#003366" onLoad="javascript:go(
'<%request.getParameter("val");%>')" >

the source in the browser is
<body text = "#003366" onLoad = "javascript:go('')" >

and it shows an empty alert box. It also goes on to pop up an empty
window.

<%
String name=request.getParameter("val");
out.println("url= "+name);
%>
Using the above statement in the jsp body does return me a proper url
which is printed on the same page.

cheers
Sunil

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #6

P: n/a

oops, did not use the '=' in <%=....%>. got tht working now.

Thanks
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #7

P: n/a
On 30 Sep 2004 23:29:59 GMT, Sunil Kamath <su************@yahoo.com> wrote:

[snip]
the source in the browser is
<body text = "#003366" onLoad = "javascript:go('')" >
and it shows an empty alert box. It also goes on to pop up an empty
window.

<%
String name=request.getParameter("val");
out.println("url= "+name);
%>
Using the above statement in the jsp body does return me a proper url
which is printed on the same page.


Then your problem must be on the server, and not with Javascript.

Ask in the JSP forum on Sun's website. I also believe JSP is on-topic in
one (or possibly more) of the comp.lang.java.* groups.

Good luck,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #8

P: n/a
Lee
Sunil Kamath said:

Sorry, but at the end of the day, typing full words (when one can do
with abbreviations and get the message across)is the last thing on my
mind. hehehehehe!!!!


You're asking people to help you.
You owe them the courtesy of making your post as easy to read as possible.

Jul 23 '05 #9

P: n/a
Ranbir Kaur wrote:
In article <opse428pr2x13kvk@atlantis>, Michael Winter wrote:
On 30 Sep 2004 03:58:43 -0700, Sunny <su************@hotmail.com> wrote:
> <!--


It's not necessary to hide scripts from browsers any more. Remove the
comment delimiters.


It's useful though, since some site-search engines are prevented to index
script blocks through this. A good example is PHPdig.


Then this app(s) is/are b0rken. It/They should not index script elements
at all (or at least should provide a pref to do so), whether "commented out"
or not.
PointedEars
--
Clarity of thought before rashness of action.
Jul 23 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.