JSP/JSTL equivalents to PHP

Hello all. I was recently advised by another forum member to use JSTL to develop a system I am developing which is web based and accesses an Oracle Db.

I am familiar with basic PHP in that you can define functions like register_user or login etc, whatever it may be, you write the code and process the data then out put it - all in that PHP (or another).

You can "include" other PHP files to be loaded that provide functionality when another file is loaded, like, functionality to connect to a database or whatever it might be.

Now I know I can do the same using JSP and JSTL, I know I can use the <jsp:import directive to import JSPs. To provide functionality, should I create custom tags that contain java "scriptlets" (for want of a better word) and then call these tags to process whatever they process ?

Or can I do something similar to PHPs, create some methods, say , some Db manipulation methods, bundle them all in a DbFunc.jsp for example, include that file to be loaded prior to accessing it's functions and then call these methods from within the JSP file that I am using ?

There will be a small finite set of functions (initially), login function, insert data function, edit data function, register user, communicate with another user function, delete data function, search for user function and search for data function. I can work out the java/JSTL coding for these, I'm just not sure how to store the code, servlet, scriptlet, JSP, tagfile, Bean etc etc. I'm confused. HELP !

Message was edited by:

MrVenjer

Message was edited by:

MrVenjer>

[1628 byte] By [MrVenjera] at [2007-10-2 23:14:28]
# 1

Well the standard MVC approach would be to handle any of those "functions" you defined with Servlets. You may want to look up terms like "MVC", "Model2". [url http://www.javaworld.com/javaworld/jw-12-1999/jw-12-ssj-jspmvc.html]link[/url]

Servlets/beans should handle the actions like registering/logging in/loading/saving.

When the servlet has done its action, it should then forward to a jsp to display the result.

>Or can I do something similar to PHPs, create some methods, say ,

>some Db manipulation methods, bundle them all in a DbFunc.jsp

Java/JSP is not like php in this regard. Rather you should define methods in a java bean/class. There should be no scriptlet code required on a JSP.

With DBAccess, one pattern to follow is the DAO, or DataAccessObject pattern. That bundles all your load/save code into one java class. YOu would normally call these methods from a servlet rather than a JSP.

Hope this helps,

evnafets

evnafetsa at 2007-7-14 6:28:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...