wood burning stoves 2.0*
The moose likes JSP and the fly likes Help for a beginner- ASPLike functions in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Help for a beginner- ASPLike functions in JSP" Watch "Help for a beginner- ASPLike functions in JSP" New topic
Author

Help for a beginner- ASPLike functions in JSP

David Eilloc
Greenhorn

Joined: Jul 19, 2001
Posts: 12
Hi there,
If anyone can help push me in the right direction it would be most appreciated.
I need to do a JSP page but I need to reuse some 'Functions' (ASP like functions, pass some variables into it, get desired output back!).
How do I implement these functions into the ASP page, I keep getting errors like :
Error: No match was found for method "createDateBoxes(java.lang.String, int, int, int, int, int
This happens when I try and put my
public String createDateBoxes(String....
.....
}
directly into the JSP page.
Should I be making it a Java class? Why can't I include it directly into the JSP page? Why is it not WORKING (sorry, getting a wee bit frustrated here.....)
Any help would be appreciated.
Cheers
David Eilloc
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60058
    
  65

One of the best ways to figure out how JSP works is to look at the java file that is generated. What you would probably see in your instance is that the method you are declaring is inlined within another method. Oopsy!
If you placed the method declaration within the JSP declaration delimiters <%! ... %>, the JSP container knows to make that a declaration within the servlet that is generated.
I'd argue however that the best place for such methods would be in a bean that helps to keep Java OUT of the JSP pages, and that can be resued across pages.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

I'll confess I've written a few function definitions in JSPs, but now I've seen the light
Actually, while Microsoft used the fact that their .NET demos had fewer source files than the J2EE equivalents as a bragging point, at the enterprise level it's really much cleaner to keep the code in a code file and the markup in a markup file - something that ASP isn't noted for.
While it's slightly more work that way, it's easier to maintain the page markups if they aren't cluttered with code. Relatively few HTML editors do well with big chunks of non-markup code splattered all over the page. Also, if you ARE working at an enterprise scale, the actual markup may be handled by an artistic-type person who's not that familiar with programming, so it's safer to put the code somewhere it's not as likely to get damaged.
It's easy to call code from a JSP - the compiled classes go in the WEB-INF/classes directory (or WEB-INF/lib if they are in a JAR file). If you haven't tried Ant (http://jakarta.apache.org/ant), I recommend it - it's simple to use and can handle the drudge work involved in building and deploying web apps.
And, of course, don't forget JSP tags! One of the neat things about JSP is that you can define your own custom "HTML" tags. That way page artists can plop down active logic requests in HTML format and never get into Java code at all.


Customer surveys are for companies who didn't pay proper attention to begin with.
David Eilloc
Greenhorn

Joined: Jul 19, 2001
Posts: 12
Cheers guys!
That has made things a little bit clearer. Just a wee bit of bg info, I am an ASP developer that needs to do just this one thing in JSP/Java.
I just didn't really know where to start, and you guys have pointed me in the right direction.
Virtual pints on me!
David Eilloc
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help for a beginner- ASPLike functions in JSP
 
Similar Threads
Problem with "HTTPUnit with JavaScript"
XML on JSP
Assignments on Strings
JSP adn buttons
How Do I Forward/Redirect Extra Parameters From JSP To ASP via POST?