BEST PRACTICES - Java By www.PPTSWorld.com. Configuration Use global-forwards/results Helps to avoid duplicate jsp files and redundancy forward mapping.

Slides:



Advertisements
Similar presentations
JSP and Servelets.
Advertisements

MWD1001 Website Production Using JavaScript with Forms.
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Java Script Session1 INTRODUCTION.
Web Development with Karsten Schulz Terp-Nielsen Master Principal Sales Consultant Oracle Denmark.
Apache Struts Technology
Coding Standard: General Rules 1.Always be consistent with existing code. 2.Adopt naming conventions consistent with selected framework. 3.Use the same.
Struts 2 Interceptors By, Srinivas Reddy.S
The Web Warrior Guide to Web Design Technologies
1 Chapter 5 – Handling HTML Controls in Web Pages spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
Q: According to Intel, the Pentium conforms to the IEEE standards 754 and 854 for floating point arithmetic. If you fly in aircraft designed using a Pentium,
Apache Struts Technology A MVC Framework for Java Web Applications.
Session-02. Index. Jsp in Struts 2 Web.xml File in Struts 2.
1 Guide to JSP common functions 1.Including the libraries as per a Java class, e.g. not having to refer to java.util.Date 2.Accessing & using external.
UNIT-V The MVC architecture and Struts Framework.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Java Server Pages (JSP) Presented by: Ananth Prasad & Alex Ivanov May 10, 2001.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
JavaScript Form Validation
MIS 3200 – Unit 6.2 Learning Objectives How to move data between pages – Using Query Strings How to control errors on web pages – Using Try-catch.
Chapter 3 Using Validation Controls. What is a Validation Control? A control that validates the value in another control Renders as an HTML tag with an.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
CSCI 6962: Server-side Design and Programming Validation Tools in Java Server Faces.
Chapter 17 - Deploying Java Applications on the Web1 Chapter 17 Deploying Java Applications on the Web.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
1 JavaScript. 2 What’s wrong with JavaScript? A very powerful language, yet –Often hated –Browser inconsistencies –Misunderstood –Developers find it painful.
Design Patterns Phil Smith 28 th November Design Patterns There are many ways to produce content via Servlets and JSPs Understanding the good, the.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Struts J2EE web application framework “ Model 2 ” Model View Controller Controller Servlet Key features XML metadata Struts taglib Simplified form validation.
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
Oracle Application Express Security. © 2009 Oracle Corporation Authentication Out-of-the-Box Pre-Configured Schemes LDAP Directory credentials Oracle.
Using Client-Side Scripts to Enhance Web Applications 1.
NMD202 Web Scripting Week3. What we will cover today Includes Exercises PHP Forms Exercises Server side validation Exercises.
JSTL Lec Umair©2006, All rights reserved JSTL (ni) Acronym of  JavaServer Pages Standard Tag Library JSTL (like JSP) is a specification, not an.
Simple MVC. An example: join.jsp
CSC 2720 Building Web Applications Server-side Scripting with PHP.
Java Web Development with NetBeans IDE -- Kai Qian Chapter 5 JavaServer Faces (JSF) Technology.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
Introduction to JavaScript CS101 Introduction to Computing.
Exceptions, cont’d. Factory Design Pattern COMP 401 Fall 2014 Lecture 12 9/30/2014.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
Page 1 Controller Action2.java Struts- config. xml Mappings Business Logic Layer Data Layer View Layer Business Bean 1 Jsp Engine Jsp 1 Action3.java Action4.java.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
Unit 10 – JavaScript Validation Instructor: Brent Presley.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
13 Copyright © 2004, Oracle. All rights reserved. Adding Validation and Error Handling.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
Architecture Multi Layered Architecture (n-tier): Application: Model Controllers Database Access Graphical User Interface (GUI): Forms, components, controls.
Struts Framework Day-2 Ashok Chakravarti. DataSource Usage Sample Struts-config.xml …
Implementation Struts Framework for well-architectured web applications Model-View-Controller design pattern.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Text INTRODUCTION TO ASP.NET. InterComm Campaign Guidelines CONFIDENTIAL Simply Server side language Simplified page development model Modular, well-factored,
APACHE STRUTS ASHISH SINGH TOMAR ast2124. OUTLINE Introduction The Model-View-Controller Design Pattern Struts’ implementation of the MVC Pattern Additional.
SDJ INFOSOFT PVT. LTD. 2 BROWSERBROWSER JSP JavaBean DB Req Res Application Layer Enterprise server/Data Sources.
Apache Struts Technology A MVC Framework for Java Web Applications.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
Model View Controller. MVC is the separation of model, view and controller. It's simply a paradigm; an ideal that you should have in the back of your.
A Presentation Presentation On JSP On JSP & Online Shopping Cart Online Shopping Cart.
Struts 2 Development. Topics  Roles in Struts Development  Control Flow  Actions  Struts 2 Views and Target  Struts 2 Custom Tags  Validation 
Testing and Debugging.
AJAX.
Unit 6-Chapter 2 Struts.
Web Programming– UFCFB Lecture 17
The Model Layer What is Model?
JavaScript Session III
Presentation transcript:

BEST PRACTICES - Java By

Configuration Use global-forwards/results Helps to avoid duplicate jsp files and redundancy forward mapping in all the actions in struts.xml – E.g Global error pages Success message pages.

Base class Have a Base class for each of the layers used This will help - – common operations need to be included in all the classes in each layer can be defined/implemented in the base class to reduce code redundancy E.g. Methods to read data from properties – Have base class implement multiple interfaces required, so that each subclass need not implement them. E.g. In struts2.0 base action class can implement multiple interfaces like SessionAware, ServletRequestAware, ServletResponseAware, ServletRequestAware, etc.

Application start up servlet Create a servlet class and have it invoked while application status up. Include methods – – To load static data from data base which is frequently accessed. This will reduce the DB calls – To read properties from property file. This will eliminate the I/O operation, when ever a property value is need to be read and used.

Exception handling Define a Application level Exception handling mechanism, and configure struts global exception handler. Don’t throw multiple exception to the calling method in other layer’s class (e.g. business class method calling a DAO class method) to handle, Instead wrap to a user defined Exception and re throw, so that the calling method need not to handle multiple exceptions and also it eliminates the layer coupling. Don’t handle any exception other than in action layer Unless if you know what should be done on the exception condition (e.g it may call another business case on exception) Don’t handle all the exception in action class, let global exception handle the exception and forward to common error page unless if you want to catch a specific exception and show custom error message to the user.

Logging Reduce unnecessary logger statements. More the logger statement lesser the performance Avoid logging same date in multiple places of a single sequence in same class Use appropriate logger level for logging information. Don’t log each data in a separate logger statement instead concat and log them into a single logger statement. Have maximum only one INFO level logger statement in layers other than DAO to identify data flow DAO layer you method start time and end time can be in INFO.

Java Server Pages Use a global error page. Always link to Actions, never to server pages. Use the action attributes tag to avoid embedding Action extension. Use s:url to reference HTML assets. Use s:include to include pages

Handle Duplicate Form Submission The problem of duplicate form submission arises when a user clicks the Submit button more than once before the response is sent back. Handle it by using the Token interceptor, tokenSession. This checks for valid token presence in action, stores the submitted data in session when handed an invalid token and prevents double submission. Don’t use button type as submit while submitting a form thorough script to avoid duplicate form submit.

Use html:messages (instead of html:errors) For displaying error messages to the end user, use html:messages instead of html:errors

Errors To display the error messages of different categories, define these categories such as FATAL, ERROR, WARNING, or INFO, in an interface In the Action or form-bean class, you can then use the following – errors.add("fatal", new ActionError("....")); or – errors.add("error", new ActionError("....")); or – errors.add("warning", new ActionError("....")); or – errors.add("information", new ActionError("....")); – saveErrors(request,errors);

Errors (contd..) To display them according to those categories, use the following code: Or use: showError(' '); // JavaScript Function

Common best practices Use static methods for util class which contains commonly used util methods Don’t hardcode any value instead use Constance. Constance should be static final. Have only one util class for an application If server side validation is used for input values, then use separate util class for action layer to hold only the validation methods.

Common best practices - (contd..) Where ever passable use switch case statement then if else Avoid iterating a collection multiple times Avoid executing DB call with in a loop. Don’t use static instance variable in action class (Struts 2.0) Action Classes should not implement complex business functionalities, rather delegate these to the Business/Service layer Don’t use instance variable to store transactional data in spring Business Service class Don’t use egger fetching (lazy=false) for one-to-many mapping in hibernate, instead use lazy fetching (lazy=true).

Common best practices - (contd..) Don’t get hibernate session directly using session = getSession(); to execute query, instead use HibernateTemplate’s call back method.

Common best practices - (contd..) Incorrect code Session session = getSession(); String sqlQuery = "SELECT * FROM employee"; Query query = session.createSQLQuery(sqlQuery); List list = query.list(); Correct Code String final sqlQuery = "SELECT * FROM employee"; List list = getHibernateTemplate().executeFind( new HibernateCallback(){ List list = null; public Object doInHibernate(Session session) throws HibernateException, SQLException{ Query query = session.createSQLQuery(sqlQuery); list = query.list(); return list; } } );