Segregating business Logic from JSP files.
I have an application with around 150 jsp files, out of which almost half of them are containing business logic.
I am actually in a process of segregating the java code from the jsp files.
Could you please guide me in finding out the best practices, dos and don'ts while engaging in such a process.
Thanks in Advance
I've been through this hellish experience. I’m not sure any “best practices” for this exist.
gimbal2 idea of starting a new project would be ideal, if costly. The other extreme is “it works”, don’t touch ‘em until you need to change the functionality then work out the cost/befit of a rewrite for that slice.
If you really want to take this route:
How bad is the code that does not live in the JSPs? Should it be reused or avoided?
What level of functional test coverage do you have?
The approach my team and I took was to cut it down into slices and try to rewrite that slice as cleanly as possible. Where interactions between slices exist try to write a facade which calls the legacy code but looks like how you would want the new code to look.
This did not work perfectly. The facades were rarely used well and we had to drop major slices of work to complete on time leaving us with large chunks of legacy code that we can’t delete.
We started with no automated functional tests, but a goal of getting to a decent amount. We failed on this, which caused major issues - mop up lasted a month and a half after release. Drop functional slices to ensure that you end up with a solid set of automated tests. If you can not get your team to buy into this don't bother with the project.
Similar Messages
-
Seperate business logic from application logic
Hi guys,
I am looking for a good article explaining the princiaples of seperating between Business Logic & Integartion logic.
The articale will be used to exlplain the prinicples SAP PI is based on when it comes to integration between 3rd party systems (Non -SAP) missign the application layer and buisness logic.
If any one has a link to an article as such.
Will be most appriciated.
Regards.
Nimrod GisisIt seems that the general rule to making a GUI
application is to seperate the "Business Logic" from
the "Presentation Logic". This is absolutely true.
From this, I'm guessing I'll
need to package all my GUI stuff together, and all the
business logic layer stuff together.If you mean the package names and structure then I would had adapted this structure:
1. I will have a package under which I will put the application common classes and interfaces.
com.myapp.common.eventhandler.EventHandler (interface)
com.myapp.common.eventhandler.AbstractEventHandler (default implementation)
com.myapp.common.form.Form (interface)
com.myapp.common.form.AbstractForm (default implementation)2. Create for each subject area its own package:
com.myapp.product.AddNewProductForm
com.myapp.product.AddNewProdcutEventHandler
com.myapp.sales.PriceListEeventHandler
com.myapp.sales.PriceListEeventHandler
The GUI will then talk to the Biz lay through an
interface right?As I illustrated through my previous example, you should have common interfaces and you might need to create Abstract classes that encapsulates the common implementation for these interfaces, then for each GUI Form or Web Page you will create its specific implementation class which inherits from the abstract class.
Finally if you were asking about the deployment packaging:
1. Create for each EJB its own jar file then bundle these Jar files under one module jar file, which represents the EJB module.
2.Package the web application (JSP, Servlets, HTML, Images, CSS, and Java script) in one Web module WAR file.
3. Package your client application module in its own jar file.
4. Assemble the EJB module Jar, Web module War, and Client module Jar in one J2EE package which will be an EAR file so that your whole package will be assembled in one EAR file at the end.
Try the "Application Assembly Tool" which comes with WebSphere. It will organize your application and facilitate this kind of integration.
- Sherif. -
Problem with accessing init parameters from JSP file
Hi,
I have my init parameters and Jsp configured in web.xml
<servlet>
<servlet-name>TestJsp</servlet-name>
<jsp-file>/Test.jsp</jsp-file>
<init-param>
<param-name>username</param-name>
<param-value>Balboa</param-value>
</init-param>
</servlet> How do I access 'username' field from JSP file.
Kindly help.
Thanks.you can do this in the jsp
<%=config.getInitParameter("username")%>or do it in the jspInit method in the jsp:
<%! String userName = null;
public void jspInit() {
ServletConfig config = getServletConfig();
userName = config.getInitParameter("userName ");
%>
Hello <%=userName%> -
How to design application to decouble business logic from GUIs on SAP N7.0
Hi guys,
How should I go about designing a program, so that I can decouple the business logic from GUI in ABAP in such a way that I can change the GUI easily or use different GUIs eg. on a scanner etc..You may use BDT (business data toolset). It's rather complex. Or use web dynpro but also complex. Or you can program it by yourself (much less difficult).
-
Hi
is it possible to call any method with in the class except handle method from jsp file?You can call , but it would not be a good design approach.A droplet can do the same task for you.
otherwise :
eg :
<%@ page import="com.mypackage.MyClass"%>
for Static access :
<%
String test= MyClass.myMethod();
%>
for normal classes :
<%
MyClass object = new MyClass();
String test= object .myMethod();
%>
http://stackoverflow.com/questions/10918526/call-java-method-in-jsp-file
http://www.javaworld.com/javaworld/jw-05-2003/jw-0523-calltag.html?page=2
```
Praveer
Edited by: Praveer Rai on Mar 26, 2013 5:08 PM -
Calling oracle reports from jsp file
how to pass parameters from jsp file oracle reports.i am getting reports wihtout passin parameters.
pls help me
urgent
vasavadattaKarthik,
You might want to repost this question to the reports forum - you'll be more likely to get a response from a reports expert.
Thanks
Blaise -
How to run .ksh file in unix from .jsp files
Hi frnd,
How to connect unix servers from .jsp file & I want to run unix scripts .ksh files from .jsp files
Thanku
bhupathipawanIt is usually a bad idea to do any major processing directly within a JSP. It is better to create a helper class and invoke methods on that. This helper class can then be tested outside of the inhospitable JSP environment.
To run the '.ksh' file you will need to use either Runtime.exec() or the more modern ProcessBuilder. You will save yourself a lot of grief if you read thoroughly the 4 sections of http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html and then implement the recommendations.
Note - although the 'traps' article is written around the use of Runtime.exec(), it's content is equally applicable to ProcessBuilder. -
Design ?: how much business logic in JSP?
Hello everyone --
I can't seem to make up my mind and my collegues aren't helping, so maybe a few of you could offer your opinions.
I have a simple JSP that is just a web interface to a database and right now I have the business logic (an entire class called TalkToDb) completely separated from the JSP in another file. The JSP isn't really THAT dynamic (I don't even have links); the top part is just a series of forms that query and update the db. It's the bottom part that has dynamically-generated tables populated by db info.
The question is, does the business logic really need to be separated from the presention stuff? Is it really dumb integrate my TalkToDb class into the JSP? What are arguments for doing it one way over the other? Thanks a heap for any feedback at all,
-Kwj.For a simple, one page project, you don't gain much in speed and development time by separating the logic, but it's a bad habit to get into if your goal is to develop sophisticated web applications. The rule I develop with is "if they tell me they want one page, anticipate them wanting ten pages". You never know where a "simple" app will grow. Using a class to handle your logic is a better design.
If you are confident that the project is going to be a quick, cut and dry database query and results display, then you can put it all in the JSP page, but just know that you are decreasing scalability for the tradeoff of quicker development.
No one will tell you that you did it wrong if you use a class and a JSP page together. However, you open yourself up to criticism from people looking for more sophisticated designs if you throw it all in the one page.
Now, that all being said - I have a few single page JSP's that we didn't want to create entire apps for. We just put the whole report logic right on the page. But the majority of my projects are well designed MVC applications.
Michael -
How to create Business partner from uploaded file by Function module?
Hi Experts,
I have uploaded Business partner data from a file to server now from individual records I have to create Business partner and have to update the records in the tables. Means from on record i have to create one business partner in sap system.
I have uploaded the records in the system and stored in a internal table.Now my task is to create business partner and have to update tables.
I need a function module which create BP by each records uploaded and update the respective tables of BP and exports business partner ID.
Please respond soon Its a requirement form the client.
Prem.HI,
You can use the bapi 'BAPI_BUPA_CREATE_FROM_DATA' to create a business partner .
call function 'BAPI_BUPA_CREATE_FROM_DATA'
exporting
businesspartnerextern = g_bpartner-partn
partnercategory = partnercategory
partnergroup = partnegroup
centraldata = centraldata
centraldataperson = centraldataperson
centraldataorganization = centraldataorganization
* CENTRALDATAGROUP =
addressdata = addressdata
* DUPLICATE_MESSAGE_TYPE =
* IMPORTING
* BUSINESSPARTNER = G_BPARTNER-BUSINESSPARTNER
tables
telefondata = telefondata
faxdata = faxdata
e_maildata = e_maildata
return = return
* ADDRESSDUPLICATES =
addressnotes = addressnotes. -
I want to send a value from JSP file to another JSP file without..
I want to send a value from one.JSP file to another two.JSP file without to show the content HTML of the one.JSP in two.JSP (with include), only take the values processed in a Bean :
===================
Bean
package pck;
import java.io.*;
public class yyyy {
public String getXxx() {
return cccc;
========================
one.JSP
<jsp:useBean id="idBean" class="pck.yyyy" scope="??"/>
<%idBean.setXxx(ccc);%>
========================
two.JSP
<%@ include file="one.jsp"%>
<%=idBean.getXxx()%>
but without to show the content HTML of one.JSP in two.JSP.
Can someone help me?, please.Why don't just put the common code in a separate file and include it in both. i.e. the code that is in one.jsp that is needed by two.jsp could be put in a common file and included in both pages, thus the HTML is separated off. If this will not work, set a boolean value in two.jsp that can be used by one.jsp to decide if the HTML should be displayed or not.
Steve -
Problem for ResourceBundle calling from jsp file
Hi, I am using WebLogic 5.1 in Solaris 8
I use java.util.resourceBundle to get the information from a .properties
file
I put the properties file in /opt/weblogic/myserver/serverclasses
When I call the properties file from EJB, It seems to be OK
But when I call the properties file from JSP using the same script, It said
the properties files not found
The Error message is:
<ServletContext-General> Servlet fail
ed with Exception
java.util.MissingResourceException: Can't find bundle for base name
test.dbini,
locale zh_TW
at
java.util.ResourceBundle.throwMissingResourceException(ResourceBundle
.java:707)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:679)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:546)
at
jsp_servlet._test._global_95_variable._jspService(_global_95_variable
.java:85)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:105)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:123)
at
weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletCon
textImpl.java:742)
at
weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletCon
textImpl.java:686)
at
weblogic.servlet.internal.ServletContextManager.invokeServlet(Servlet
ContextManager.java:247)
at
weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.jav
a:361)
at
weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:261)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
PLease Help!!
Regards,
Fannie
Hi,
open dataset file for input in text mode.
check sy-subrc = 0.
while sy-subrc = 0.
read dataset file into wa.
if sy-subrc = 0.
append wa to itab.
else.
exit.
endif.
endwhile.
close dataset file.
regards
Siggi
PS: check also the F1-help for open, read and close statements! -
Calling RDF files from JSP files
Hi,
I created a report file using Oracle 9i Report Builder and save it as RDF extension.After that I deployed it into the server and it's working properly.But, when I created a simple JSP file(not a report) and try to call that RDF file from this JSP file,the web browser prompts for downloading the entire RDF file.Is there any way to aviod this prompting, and make it to proper ruuning from that JSP ??
Thanks &Regards
Rajesh K.RYou are in the wrong forum
Go to Reports -
Problem Accessing Class in my package from jsp file
Hi,
I am using Apache tomcat server and i have made package which contains a class for database connection. I have imported this package in my jsp file but when i run the jsp tomcat gives the class not found exception. i have placed the jsp file in /webapps/my_project/ folder and the package in the /webapps/my_project/WEB-INF/classes/ folder.
Still its not working.
Please help me out!!!!!!!!hi,
Thanks for ur reply. You have guessed it right, i dont have a .jar file its a .class file in a package subfolder. I have tried out ur suggestion but it didnt work. The following error i shown when i run it.
org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
C:\Apache Tomcat 4.0\work\localhost\_\College\test$jsp.java:4: Package college_lib not found in import.
import college_lib.*;
^
1 error, 1 warning
Here, College_lib is the package name which contains the class my class file
Is there any problem with my Apache Tomcat4.0 or any other thing.
Message was edited by:
Despo -
Where are the .java files compiled from .jsp files stored?
hi,
I'm new to weblogic server. When I use Tomcat as the jsp server, it compiles .jsp
files to .java files and then .class files. So when an error reported I can track
it in the .java file.
But what should I do with weblogic? It only saves the .class files in the work
dir. Or is there a better way to trace errors in jsp files?
Thanks!
This should give you the information you need to set the keepgenerated flag:
http://e-docs.bea.com/wls/docs60/jsp/admin.html#53346
Also, the .java files will be right next to the .class files with are under
a tmp directory in the /WEB-INF directory under the WEB-INF if it is an open
directory or in the
config/mydomain/applications/.wl_temp_do_note_delete/WEB-INF directory if it
is .war file.
Sam
"Raymond" <[email protected]> wrote in message
news:3b931619$[email protected]..
>
> Thanks, but can you tell me more about it? where to set this flag? I'm
using WLS
> 6.0sp1.
>
> "Sam Pullara" <[email protected]> wrote:
> >You can turn on the keepgenerated flag if you want to keep the .java
> >files.
> >How you do this depends on what version you are using.
> >
> >Sam
> >
-
Use javabean object from jsp file
I try to use JDBC to open database, find my record and initiate and return a static object of javabean class. In my jsp file, I try to use this object, but it is null. My directory is C:/tomcat/webapps/myapp/web-inf/classes/bean. A "jsp" folder is under "myapp" directory. I put jsp file in "jsp" and bean class in "bean".
Is there some one can give me some suggestions?
thank you!
QiangI assume that the constructor for your object is inside the static method.
If the static method returns null, then the object is not being constructed.
There is nothing wrong with the JSP.
Thus the best place to look will be inside the static method. Use tracers like System.out.println() and printStackTrace() and I am sure u will find the problem.
One thing was not very clear to me. If u construct your object within the static method, there must be some reason for that. Since you are using parameters, this does not look like a singleton. Rather I think it is one object per input combinations you have provided. It is interesting as I have never seen this kind of code before(Except session EJB) It will be a nice learning experience if you post some documents regarding your design.
Shubhrajit
Maybe you are looking for
-
When I attempt to add files to...or copy to the desktop of my mac, my icloud (idisk ..the blue icon on my desktop) is giving this error: The operation can't be completed because one or more required items can't be found. (Error code -43) I've been se
-
When I try to download an audiobook from my iTunes Library I get the message that 'it was not copied because it cannot be played on this iPod. I had just downloaded another audio book from the same library to the same iPad so don't know what the pro
-
Need to "Place" Images on White Coffee Mugs
I am creating virtual samples of several hundred coffee mugs using PS CS 5.5. (I have access to CS6 but haven't installed it.) There will be two views of each mug, front and back. The images to be wrapped around the mug are PDFs of identical rectangu
-
HT4101 Which is better Ipad smart cover or case
I am getting a new Ipad 3rd Gen 32GB and I wonder if it is a good thing to purchase either a smart cover or case? Another question I have is it wise to get a wireless keyboard?
-
Reg How to Update DeleteFlag Image (Default N) Value in Table
Hi Friends, I have One Column Delete Button(Style Image) in Advanced Table So Based on That Delete Button Click I need to Update Value in Table(DeleteFlag =Y ) So How to Update Value in Table(Data Base). Select empno,deleteflag from Emp where empno=: