[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Ebedding JavaScript or printing it to jsp/html page through Java

Posted on 2005-05-17
2
Medium Priority
?
152 Views
Last Modified: 2010-03-31
Hi Experts,

I would like to find out an efficient / appropriate way to display JavaScript in a jsp page; the JavaScript changes based on values in my Java code.  For now I've been using the out.println, as show bellow, to put into the jsp page but I'm not sure if that's how its supposed to be done.  Any recommendations or words of wizdom?

              switch ($nFrame) {
                        case 1:      // Top frame
                            global.out.println("<html>");
                            global.out.println("<head>");
                            global.out.println("<title>"+ frameTitle +"</title>");
                            global.out.println("<script language=\"JavaScript\" type=\"text/JavaScript\">");
                            global.out.println("<!--");
                            global.out.println("function TabClick(href, target) {");
                            global.out.println("");
                            global.out.println("if (window.parent.parent.NewPageLoading == \"YES\") {");
                                global.out.println("alert('ANOTHER PAGE IS CURRENTLY BEING LOADED. PLEASE TRY AGAIN AFTER THIS LOADING SESSION HAS ENDED.')");
......
....
.....
0
Comment
Question by:kasiencja
1 Comment
 
LVL 29

Accepted Solution

by:
bloodredsun earned 1200 total points
ID: 14021115
Is this in a servlet or a JSP?

it looks more like a servlet as you are embedding HTML in Java code. In a JSP you should embed the Java code in the HTML.

e.g.
MyPage.jsp
----------
<%
//blah, some processing
%>
<html>
<head>
<title><%=frameTitle%></title>
<script language="JavaScript" type="text/JavaScript">
<!--
<%
 switch ($nFrame) {
  case 1:     // Top frame
%>
    alert('AN ALERT');
<%
 break;case 2:
%>
    alert('ANOTHER ALERT');
<%
break ;default:
%>
    alert('DEFAULT ALERT');
<%
break;
}%>
-->
</script>
</head>
<body>
//blah, rest of code


0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question