JSP: Custom Tags #37

  • Custom Tags = alternatives to java beans for JSP = reduces some limitations of JavaBeans (in JSP) like to few methods to access the bean, you may still require to write much java code in JSP [that we want to avoid]
  • Overview:
  • Custom tag with no body should extend TagSupport class that implements Tag interface
  • Tags extending TagSupport should extend only one method – doStartTag(), and in this case the doStartTag() method should return SKIP_BODY
  • A simple tag code is shown below:
  • Next you need to define a tld file – a descriptor file for the tag – XML file.
  • In the tld files, the most important tag is the tag
  • The sub-elements of the tag element are: name, tag-class, description, body-content.
  • Sample:
      SimpleTag  tags.SimpleTag  Sample TLD File  empty
  • To use the custom tag in a JSP file, You need to provide a directive like:
     
  • Example use:
  • How to add attributes to tags: In the class, declare private variable for each attribute you want, define a setXXX method for each of the attribute
  • In the tld – file, add an attribute tag for each attribute you want. This attribute tag can have following sub-elements: name, required, rtexprvalue = can the value be an expression, type=class to which the value should typecast to, description
  • Defining tag body: doStartTag() should return EVAL_VALUE_INCLUDE
  • A new method named doEndTag() should be defined that will define what will be the effect on the body text.
  • The doEndTag() method may return EVAL_PAGE = continue to process rest of the JSP page, SKIP_PAGE = stop processing rest of the page
  • To support body inside the custom tags – body-content tag in the tld file needs to be adjusted: example
      SimpleTag  tags.SimpleTag  Sample TLD File  JSP
  • Example use: Body Text

From: http://sitestree.com/?p=4964
Categories:37
Tags:
Post Data:2012-12-20 05:06:38

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

JSP: Random Information #37

  • Three JSP constructs: scripting elements, actions, directives
  • Scripting elements: expressions, scriptlets, declarations
  • Expression = translates to println in servlets in _jspService methods
     < % = expression %> < % = new java.util.Date() %>

    inserts values directly to the output

  • scriptlet: block of java code : directly inserted into the related servlets in the _jspService method:
    < % java code %>
  • declarations:
    < %! variable and method declarions%>

    Directly placed in the body of the translated servlets

  • >= JSP 1.2 : XML Syntax for expressions, scriptlets, declarations
    Java ExpressionJava CodeJSP Declaration
  • JSP implicit objects: request, response, out, session
  • Implicit objects: application = servletContext = persistent data, config = ServletConfig = initialization parameters, pageContext = context to store reference to objects, and page = this, exception = used by error pages :
  • < %@ directive attribute ="value " %>< %@ directive attribute1 ="value1 " attribute2 ="value2 " ... attributeN ="valueN " %>
  • JSP Directives : page, include, taglib
  • page directive attributes: import, extends, session, isThreadSafe, buffer, autoFlush, contentType, pageEncoding, errorPage, isErrorPage, language, and info
  • < %@ page import="package.class " %>< %@ page import="package.class1,...,package.classN " %>< %@ page extends="somepackage.someclass " %>< %@ page session="true" %>< %@ page session="false" %>< %@ page isThreadSafe="true" %>< %@ page isThreadSafe="false" %> < %@ page buffer="none" %>< %@ page buffer="sizekb" %>< %@ page autoFlush="true" %>< %@ page autoFlush="false" %>< %@ page contentType="MIME-Type " %>< %@ page contentType="MIME-Type ; charset=Character-Set " %>< %@ page contentType="video/mpeg" %>< %@ page pageEncoding="GB_2312-80" %>< %@ page errorPage="Relative URL " %>< %@ page info="Some Message " %>
  • XML Syntax
  • Other directives:
  • < %@ include file="relevantURLspec " %> : output of another file
  • JSP Custom Tag:
     < %@ taglib uri="TagLibraryURI " prefix="someprefix " %>
  • JSP Pages and Java Beans: JSP page can include logics in Java Code – not recommended – rather embed code into beans or custom tags
  • JavaBean: basically a class, visible, also invisible: JSP supports both types:
  • JavaBeans are accessed through Introspections :
  • Introspection: a class that extends BeanInfo Interface
  • JSP action tags for Java Beans: jsp:useBean, jsp:getProperty, jsp:setProperty
  • jsp:useBean: attributes: id, class, scope=(page,request,session,application), beanName, type,
  • jsp:getProperty: name = name of the bean = id of jsp:useBean, property = property to access
  • jsp:setProperty: attributes: name = name of the bean = id of jsp:useBean, property = property to access, value = value to set, use param attribute to extract from request object for setting values
  • To use a bean from JSP page, place the bean class file in one of the accessible servlet directories
  • Custom Tags = alternatives to java beans for JSP = reduces some limitations of JavaBeans (in JSP) like to few methods to access the bean, you may still require to write much java code in JSP [that we want to avoid]

From: http://sitestree.com/?p=4963
Categories:37
Tags:
Post Data:2007-04-22 17:46:00

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

JSP Expression Language #37

Expression Language-------------------Introduced in JSP 2.0You can write short expressions for different operations [other than using functions]If you want to ignore EL in any page addSome examplesEL=> what does it mean?${3+2-1}=> ${3+2-1} ${"1"+2} => ${"1"+2} ${3%2} => ${3%2} ${(8 div 2) mod 3} => ${(8 div 2) mod 3} ${1<2} => ${1<2} 

From: http://sitestree.com/?p=4793
Categories:37
Tags:
Post Data:2010-01-28 02:13:10

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

JSP Tags #37

JSP Tag Library (JSTL)

JSP Disadvantage
1. Java code embedded in scriptlets make the
                                
                                         code difficult to understand
2. Reduced code reusability
3. Difficult to modify [Java Code]
4. Java code needs to use Class Casting

JSTL Advantages

1. Better code
2. Enhanced Code reusability
3. No type casting from the request and session objects
4. Expression Language in JSP makes it easier to call getter and setter methods.

Drawback

1. Adds overhead as JSTL adds more into the resultant Servlet
2. Can not do all that Java code can do


Four Libraries:

Core: Basic tags like loops, conditions, and input/output
fmt: Format like date format
xml: XML processing
sql: Database access


Core Tag Library

<%@ taglib prefix="core" uri="http://java.sun.com/jsp/jstl/core" %> 
<core:set var="var" scope="session" value="..."/> 

Conditional
<core:if test="${condition}"> </core:if> 
<core:choose>
     <core:when test="condition1" >
     ...
     </core:when>
    <core:when test="condition2" >
    ...
    </core:when>
    <core:otherwise>
    </core:otherwise>
</core:choose>

<core:otherwise> will be executed only and if only all other conditions fail.


Iterator

Iterator tages are used to traverse an array of objects and process each object (when required)
<c:forEach var="item" items="collection">
</c:forEach>

or

<c:forEach begin="0" end="10" varStatus="status" step="1" >
</c:forEach>


Function Tag Library

Basic String Functions
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 

Example
<%@ taglib uri="/WEB-INF/fn.tld" prefix="fn" %>
<%@ taglib prefix="core" uri="http://java.sun.com/jsp/jstl/core" %> 

<core:set var="test" value="Hello World"/>
Index of l is :- ${fn:indexOf(test, "l")}<br>

From: http://sitestree.com/?p=4792
Categories:37
Tags:
Post Data:2007-12-05 06:15:58

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

Creating Custom Tags in JSP #37

How to create custom tags in JSP?You can create custom tags in JSP. Steps:-----1. You have to create a Java file that will define the operation of the custom tag2. For the Java file, you have to extend javax.servlet.jsp.tagext.BodyTagSupport class3. in your implementation, you have to override (re-write) doStartTag(), doEndTag(), and doAfterBody() methods4. Create tag library description file(XML file with .tld extension).Example-------Implement a tag that reverses a stringimport java.io.IOException;import javax.servlet.jsp.JspTagException;import javax.servlet.jsp.JspWriter;import javax.servlet.jsp.tagext.BodyContent;import javax.servlet.jsp.tagext.BodyTagSupport;public class ReverseTag extends BodyTagSupport {    private static final long serialVersionUID = 1L;            //override doStartTag    public int doStartTag() throws JspTagException{        return EVAL_BODY_TAG;    }            //override doEndTag    public int doEndTag() throws JspTagException     {      try {           JspWriter out = pageContext.getOut();      } catch (Exception ex) {           throw new JspTagException("Exception" + ex);      }    return SKIP_BODY; }//reverse the text    public int doAfterBody() throws JspTagException {    BodyContent body = getBodyContent();    try {            JspWriter out = body.getEnclosingWriter();            //get text inside the tag            String bodyContent = body.getString();            //reverse the text            if (bodyContent != null) {                for (int i = bodyContent.length() - 1; i >= 0; i--) {                    out.print(bodyContent.charAt(i));                }            }            out.println();            body.clearBody(); // Clear for next evaluation          } catch (IOException ioe) {               throw new JspTagException("Exception at doAfterBody " + ioe);     }        return (SKIP_BODY);    }}5. Create the taglib descriptor    1.0    1.1                    stringreverse        net.justetc.taglibrary.ReverseTag                    Reverse the text            6. Example use of the custom tag    Custom Tag library
justetc

From: http://sitestree.com/?p=4791
Categories:37
Tags:
Post Data:2010-05-23 22:42:48

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

SQL Server Short-notes at JustETC #38

How to optimize query response time?

How to optimize SQL Server Cursors

What are cursors?

SQL Server Hints

Scalability: SQL Server 2005

Scaling Out

Dynamic Management Views

SQL Server Database System Tuning

SQL Server: Index

SQL Server : Backups

SQL Server Short-notes at JustEtc

SQL Server Short-notes at JustEtc

From: http://sitestree.com/?p=5257
Categories:38
Tags:
Post Data:2009-08-28 05:17:15

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

SQL Server Short-notes at JustEtc #38

Query Optimization

How to optimize query response time?

SQL Server

How to optimize SQL Server Cursors

What are cursors?

SQL Server Hints

Scalability: SQL Server 2005

Scaling Out

Dynamic Management Views

SQL Server Database System Tuning

SQL Server: Index

SQL Server : Backups

From: http://sitestree.com/?p=5221
Categories:38
Tags:
Post Data:2012-10-04 19:57:27

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

How to optimize query response time? #38

  • Check that only the required columns are selected [in select statements]
  • Check that the right types of joins are used
  • Check that if re-ordering the joins will help or not
  • Check the indexes of the tables [is indexing done on the right columns]
  • Check that in joins you used the indexed columns in the join condition
  • Check that the operating system is configured for optimum performance [for SQL Server]
  • Use concepts like Scaling Up and Scaling Out to increase the overall performance of queries/SQL Server
  • Use Dynamic Management Views to analyze the query performance/(query execution plans)
  • Use hints to skip default query execution plan to introduce your plan for quick response. Use hints on join types or also for table index selection
  • Check that the system and the network are appropriately configured and there are no issues that can cause the performance penalty
  • Tools that may help in the analysis and improvement: DBCC Commands, Dynamic Management Views, SQL Server Profiler, SQL Server Management Studio, System Stored Procedures, and SQL Trace
  • Check these articles for more information

From: http://sitestree.com/?p=5087
Categories:38
Tags:
Post Data:2013-01-20 11:22:32

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

SQL Server : Backups #38

Why are backups needed?

To protect accidental data loss. Still, if you use highly available and fault-tolerant systems like SAN, and RAID, you may need to backup your database regularly. These fault tolerant systems can not provide accidental data delete by users, accidental data corruption from software and hardware failure. If you have a disaster recovery site or a secondary datacenter to where all data are replicated and data changes are stored, then you may not need backup but otherwise regular backups are always useful.

Data backup can restore data until the last backup. . Transaction Logs may help to restore data up to the point of failure. Restore data from the data backup, then if you have the transaction log up to the failure apply it to the data.

SQL Server Recovery Models:

  • Simple Recovery Model. Transaction logs are not used
  • Full Recovery Model: Use both data and transaction log backups
  • Bulk-logged recovery model: Like full recovery model. But here bulk operations are minimally logged to the transaction log. So full recovery becomes faster.

Types of Backups

  • Full database backup: Full database, all files and file groups are backed up
  • Partial Back up: It’s not the differential backup. Here, all primary file groups and any other file groups that are read-write are backed up. But read-only file groups are not backed up by default.
  • File or file group backup: Usefull when full back ups take too long. Backup in parts.
  • Differential back up: Backup only the changes. Should be applied to a full backup.
  • Log backup: In log back ups, transaction logs are backed up regularly. It helps in bulk logged recovery model and full recovery model.
  • Copy only backups:
  • Full text catalog backups

Knowing about backup devices, media sets, and backup history tables is also important.

Mirrored Media Sets: Backup data to more than one media at the same time.

Backup Strategy:

Based on your company need and type of data, you should come up with a backup strategy.

Some backup strategies

Strategy – 1

  1. Take full database backup every saturday night
  2. Take a differential backup every wednesday night
  3. Perform, continual transaction log backups every 30 minutes

Strategy – 2: If the database is too big, and user activities need continuous uptime and optimal performance

  1. Filegroup 1 backup every saturday night
  2. Filegroup 2 backup every sunday night
  3. File group 1 differential backup every Tuesday night
  4. File group 2 differential backup every wednesday night
  5. File group 1 differential backup every Thursday night
  6. File group 2 differential backup every Friday night
  7. Perform, continual transaction log backups every 30 minutes

Backup System Databases

It is also important to back up system databases like master, model, msdb, tempdb, distribution, resource.

From: http://sitestree.com/?p=4837
Categories:38
Tags:
Post Data:2011-02-01 01:27:56

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

SQL Server: Index #38

SQL Server: Index

  • Indexes make database access faster. Without index your queries will run but indexes can increase the performance dramatically.
  • You can define multiple indexes for a table and select the index that is required for current operations.
  • Only one clustered index is supported for a table
  • To get advantage of indexes you have to mention the index related constraints in your where clause like where last_name =’xyz’
  • If you have indexes on two or more columns, in where clause mention the first column name/constraint first [that was first in the index creation].
  • A clustered index contains table data sorted in the index where a non-clustered index contains reference to the table data or clustered index. Non-clustered indexes are both physically and logically independent of table data.

Index Best Practices

  1. Select a column/(columns) for indexes that will provide good uniqueness and selectivity otherwise indexing may degrade the performance
  2. Create indexes that result in lower number of rows to be searched
  3. Create indexes that select a range of rows
  4. Try to create clustered index with as uniqueness as possible
  5. Keep indexes as narrow as possible (not many/unnecessary columns)
  6. Don’t index very small table

In SQL server, you can create indexes through your sql statements or using the development studio interface.

From: http://sitestree.com/?p=4836
Categories:38
Tags:
Post Data:2011-01-21 05:26:33

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>