• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need to declare a function in jsp and call function

 
Ray Smilgius
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This does not compile if I take out the <% test(); %>
It works but I need to call the function for testing purposes.
when I call test() cant find class or variable test() see short code below:

<html>
<head><title>Number Guess</title></head>
<body bgcolor="white">
<% test(); %>
<!% public void test()
{
out.print("Test");
}
%>
</body>
</html>
Thanks Ray
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code is a bit wrong...
1- the correct declaration code is <%! not <!%
2- if you want to use 'out' in your test() class you need to pass it the JspWriter, or get a new instance of it.
Try this version:
 
Ray Smilgius
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much that helped alot. I will have to change all my functions.

Thanks Ray
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!