I've some question about jsp,
I've some method let say the name of the method is getStaffDetail and were written in staffDetail.jsp file below code in staffDetail.jsp
<%!
public StaffDetails getStaffDetail(int staffId) throws SQLException{
//Request to db
//process the result set
//return StaffDetail
}
%>
and this method were use in personPage.jsp file by calling it using include directive
personPage.jsp
<%@ include file = "/path/staffDetail.jsp">
<%
StaffDetails sd = getStaffDetail(1234);
String stafName = sd.getStfName();
String stfAddress = sd.getStfAddress();
//and the rest...
%>
Or should I write this code in java class for example StaffDetail.class
package packageName
import DBAccess;
public class StaffDetail{
//Request to db
//process the result set
//Setter n getter in this class
}
And in the personPage.jsp
<@ page import = "package.StaffDetail">
<%
StaffDetail sdInClass = new StaffDetail();//
sdInClass.getStfName();
sdInClass.getStfAddress();
%>
The code is quite same the only difference is instead of putting the method in the jsp file, I put in the class
I would like to ask which once better in performance.
p/s I know that we as a java web programmer are discourage to use scriplet in jsp file, but for some reason I can't convert all the scriplet to EL. The least I can do is convert the method into class file. Sorry I'm new in java programming
Well, there is no performance issue of writing scriptlets in jsp or importing java class in jsp!
In both the cases, your jsp will be automatically converted to a servlet (by jsp container) and then the servlet will eventually be compiled to byte code! And this will happen once while deploying the application and after that there is no jsp, no scriptlet, no el expression, only the compiled byte code will run in your JVM.
Scpritlets are discouraged for other reasons, mostly related to readability and maintainability of your application. There is nothing about the performance!
From my experience, I can tell you, mostly debugging is too much difficult in scriptlet jsp pages! If your application freaks out in scriptlet, you are dead! Most of the time, will see a blank page with no error message or no sufficient clue to drill through!!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With