Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP & Javascript?

 
PVS Praveen
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to access JSP Code within a javascript function.?
If yes,can anyone enlighten me please...?
 
Vikas Lamba
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Raghav Sam
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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).]
 
Jayson Falkner
Author
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic