Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Please check my jsp function code

 
Ray Smilgius
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error: 500
Location: /InScope/out.jsp
Internal Servlet Error: Unable to compile class for JSPC:\Tomcat\work\localhost_8080%2FInScope\_0002fout_0002ejspout_jsp_2.java:26: Undefined variable or class name: out out.print("" + "'\r'"); ^ C:\Tomcat\work\localhost_8080%2FInScope\_0002fout_0002ejspout_jsp_2.java:27: Undefined variable or class name: out out.print("
here is the code:
I have declared a function to replace a VB Script Function
If I compile without a function then the class out is recognized
<%@ page import="java.net.*" %>
<%@ page import="java.io.*" %>
<html>
<head><title>Number Guess</title></head>
<body bgcolor="white">
<%! public void RefreshPage(String sUrl){
//catch any errors
try{

boolean blnSkipPage = true;

out.print("<html><head>" + "'\r'");
out.print("<script language=\"javascript\">" + "'\r'");
out.print("location.href='" + sUrl + "'");
//out.print("</script>" + "'\r'");
//out.print("</head></html> + "'\r'");
}
catch(Exception e)
{
System.out.println("An error has occured at RefreshPage Function");
System.out.println(e.getMessage());
}

}//End function
%>
</body>
</html>
declared without function it works see below
<%@ page import="java.net.*" %>
<%@ page import="java.io.*" %>
<html>
<head><title>Number Guess</title></head>
<body bgcolor="white">
<%
try{

boolean blnSkipPage = true;

out.print("ray");
out.print("test");
out.print("me");

}
catch(Exception e)
{
System.out.println("An error has occured at RefreshPage Function");
System.out.println(e.getMessage());
}

%>
</body>
</html>
Thanks for any help Ray
 
Junilu Lacar
Sheriff
Posts: 10090
120
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ray,
the implied variable out is only available in scriptlets, not in declarations. To get a reference to it, you would have to pass it in from a scriptlet as a parameter.
Junilu
 
Axel Janssen
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ray.
With the ! in <%! you have JSP declaration.
JSP_engine will convert this in a method. And in this method there is simply no object with the name "out" declared.
In your 2. example you did not use "!" (scriptlet). So the code gets inserted in the _jspService method invoked when new request arrives. You can see that in Tomcat (are you using Tomcat?? If you use other try to read out javax.servlet.context.tempdir attribute) Work directory.
Its under CATALINA_HOME/work. Each virtual host has one working directory. Under this level each webapp has a directory. Finally there is a jsp directory under it. View the .java file.
You will see that the _jspService method automatically creates an JSP Writer out as local variable which is initialized with out = pageContext.getOut(); few lines later.
Hope it helps
Axel
(dont think its from me. I got it from the fat Wrox Professional JSP2 2nd ed. (when will I finish that? :roll: )
[ January 09, 2002: Message edited by: Axel Janssen ]
 
Ray Smilgius
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for your reply. I have a better understanding of what is going on now. I will investigate further and conquer this small dilemma.
Thanks Ray
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!