aspose file tools*
The moose likes Servlets and the fly likes JSP & Javascript? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP & Javascript?" Watch "JSP & Javascript?" New topic
Author

JSP & Javascript?

PVS Praveen
Greenhorn

Joined: Dec 15, 2000
Posts: 1
Is it possible to access JSP Code within a javascript function.?
If yes,can anyone enlighten me please...?
Vikas Lamba
Greenhorn

Joined: Mar 20, 2001
Posts: 4
Don't know a clean way but the following workaround might help.
In the JSP page, write the code for a Java Script function as follows:
<%
out.println("<SCRIPT LANGUAGE=\"Javascript\"");
out.println("javascriptVariable1 = "+(String)request.getAttribute("JavaVariable"));
%>
function javascriptFunction1() {
if (javascriptVariable1 == 'Test') {
....
}
}
<% out.println(""); %>
What the above code does is to allow u to set the value of a Javascript variable from a Java object lying in the JSP request.


------------------
Vikas Lamba


Vikas Lamba
Raghav Sam
Ranch Hand

Joined: Apr 12, 2001
Posts: 412
<script language="JavaScript">
function displayItems() {
newWindow = window.open("ShowItems.jsp?categoryID=<%= CategoryMaster.getCategoryID(category) %>", "displayItems", "titlebar,scrollbars,WIDTH=500,HEIGHT=600,resizable");
newWindow.focus();
}
</script>
Suppose you want to display the items of a particular category in a separate pop-up window, you can use the above script. The script will get executed on clicking a button called "Display Items". The category id is passed to the "ShowItems.jsp" page as a request parameter.
HTH,

------------------
Raghav.
[This message has been edited by Raghav Sam (edited July 06, 2001).]


Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.<br />- Dr. Seuss
Jayson Falkner
Author
Ranch Hand

Joined: May 07, 2001
Posts: 57
If you mean run a JSP function via JavaScript on the client-side. No, check out this FAQ.
JSP and JavaScript have completely different runtimes. However, it is perfectly valid to generate JavaScript code using JSP as demonstrated above.


Jayson Falkner<br />jayson@jspinsider.com<br />Author of <a href="http://www.jspbook.com" target="_blank" rel="nofollow">Servlets and JavaServer Pages; the J2EE Web Tier</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP & Javascript?