Solved

Error in JSP script

Posted on 2009-05-17
12
149 Views
Last Modified: 2012-05-07
I run the attach JSP script and I get error please I need help here
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
 
<body>
<%
	double x1 = 0.0;
	double y1 = 0.0;
	double x2 = 0.0;
	double y2 = 0.0;	
	
	for (int i=0; i < 5; i++)
	{
		if (i == 1)
		{
			x1 = 12.0;
			y1 = 15.5;
			x2 = 16.2;
			y2 = 17.8;
			
			out.print ("<a href=\"javascript:Zoom_to_Extent();\">Coordinate</a>");
		}	
	}
%>
 
<script language="JavaScript">
	function Zoom_to_Extent()
	{
		var x1 = <%= x1 %>;
    	var y1 = <%= y1 %>;
    	var x2 = <%= x2 %>;
    	var y2 = <%= y2 %>;
		
		println ("Done.");
		println (x1);
		println (y1);			
		println (x2);		
		println (y2);		
	}
</script>
</body>
</html>

Open in new window

0
Comment
Question by:bwor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
12 Comments
 
LVL 27

Expert Comment

by:rrz
ID: 24406645
I am not sure what you want here. But here is something that give you an output.
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
 
<body>
<%
	double x1 = 0.0;
	double y1 = 0.0;
	double x2 = 0.0;
	double y2 = 0.0;	
	
	for (int i=0; i < 5; i++)
	{
		if (i == 1)
		{
			x1 = 12.0;
			y1 = 15.5;
			x2 = 16.2;
			y2 = 17.8;
			
			out.print ("<a href=\"javascript:Zoom_to_Extent();\">Coordinate</a>");
		}	
	}
%>
 
<script language="JavaScript">
	function Zoom_to_Extent()
	{
		var x1 = <%= x1 %>;
    	var y1 = <%= y1 %>;
    	var x2 = <%= x2 %>;
    	var y2 = <%= y2 %>;
		
		document.write("Done.");
		document.write(x1);
		document.write(y1);			
		document.write(x2);		
		document.write(y2);		
	}
</script>
</body>
</html>

Open in new window

0
 

Author Comment

by:bwor
ID: 24409274
I need to call function and print output but your code is not print output on screen please check your code
0
 
LVL 27

Expert Comment

by:rrz
ID: 24412489
The code I posted prints the values when the link is clicked.  Please copy and paste.  If this is not what you want, then please describe your requirements more clearly.
0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 

Author Comment

by:bwor
ID: 24414131
The problem here when I click over coordinate to check values for x1, y1, x2, y2 I see only the last values. For example if I click over coordinate #1 I will see the last value not values when i =1
Please check attach code

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
 
<body>
<%
	double x1 = 0.0;
	double y1 = 0.0;
	double x2 = 0.0;
	double y2 = 0.0;	
	
	for (int i=1; i <= 5; i++)
	{
		if (i == 1)
		{
			x1 = 10.0;
			y1 = 15.0;
			x2 = 20.0;
			y2 = 25.0;			
		}
		else if (i == 2)
		{
			x1 = 15.0;
			y1 = 20.0;
			x2 = 25.0;
			y2 = 30.0;			
		}
		else if (i == 3)
		{
			x1 = 20.0;
			y1 = 25.0;
			x2 = 30.0;
			y2 = 35.0;			
		}					
		
		out.println ("<p></p><a href=\"javascript:Zoom_to_Extent();\">" + i + " Coordinate x1= " + x1 + 
		" y1= " + y1 + " x2= " + x2 + " y2= " + y2 + "</a>");
	}
%>
 
<script language="JavaScript">
	function Zoom_to_Extent()
	{
		var x1 = <%= x1 %>;
    	var y1 = <%= y1 %>;
    	var x2 = <%= x2 %>;
    	var y2 = <%= y2 %>;
		
		alert("x1= " + x1 + " y1= " + y1 + " x2= " + x2 + " y2= " + y2);
	}
 
	<!-- document.write ("<h1>Done.</h1>");	 -->
</script>
</body>
</html>

Open in new window

0
 
LVL 17

Expert Comment

by:Thomas4019
ID: 24417426
This looks to me like JSP is really not needed for what you are trying to do. I recommend for this using just Javascript. Could you clearly explain what the goal of this script is? Then i can give you help on how to write it with Javascript.
0
 
LVL 27

Accepted Solution

by:
rrz earned 500 total points
ID: 24417708
Hi Thomas, thanks for the help. I was busy all day. Yes, it is difficult to know what  bwor has in mind here. Here is some code that might be help.  
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
 
<body>
<%
	double x1 = 0.0;
	double y1 = 0.0;
	double x2 = 0.0;
	double y2 = 0.0;	
	
	for (int i=1; i <= 5; i++)
	{
		if (i == 1)
		{
			x1 = 10.0;
			y1 = 15.0;
			x2 = 20.0;
			y2 = 25.0;			
		}
		else if (i == 2)
		{
			x1 = 15.0;
			y1 = 20.0;
			x2 = 25.0;
			y2 = 30.0;			
		}
		else if (i == 3)
		{
			x1 = 20.0;
			y1 = 25.0;
			x2 = 30.0;
			y2 = 35.0;			
		}					
		
		out.println ("<p></p><a href=\"javascript:Zoom_to_Extent(" + x1 + "," + y1 + "," 
                               + x2 + "," + y2 + ");\">" + i + " Coordinate x1= " + x1 + " y1= " 
                               + y1 + " x2= " + x2 + " y2= " + y2 + "</a>");
	}
%>
 
<script language="JavaScript">
	function Zoom_to_Extent(x1,y1,x2,y2)
	{
 
		
		alert("x1= " + x1 + " y1= " + y1 + " x2= " + x2 + " y2= " + y2);
	}
 
	<!-- document.write ("<h1>Done.</h1>");	 -->
</script>
</body>
</html>

Open in new window

0
 
LVL 17

Expert Comment

by:Thomas4019
ID: 24418081
bwor, since you are initializing x1,y1,x2,y2 all on the server side with JSP, this will never change unless you reload the page.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24419003
And bwor is obviously mixing server side java with client side javascript

rrz@871311: You cannot use document.write after the load of a page. Change some element's innerHTML instead
0
 
LVL 27

Expert Comment

by:rrz
ID: 24422283
mplungian, thank you for the knowledge.
But what about the changes I made to bwor's latest code ?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24422365
That should work - e.g. not give error, but if the aim is to zoom, then instead of alert, the script needs to (ajax) call the server with the new x/y values
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

724 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