JavaSercer Pages Example 17.18. The QueryTag’s execute( ) (Christian web host)

JavaSercer Pages Example 17.18. The QueryTag’s execute( ) Method public Object execute(SQLCommandBean sqlCommandBean) throws SQLException, UnsupportedTypeException { return sqlCommandBean.executeQuery( ); } This method simply calls the bean’s executeQuery( ) method. The UpdateTag tag handler uses the bean’s executeUpdate( ) method instead, and wraps the returned int in an Integer object, as shown in Example 17.19. Example 17.19. The UpdateTag’s execute( ) Method public Object execute(SQLCommandBean sqlCommandBean) throws SQLException, UnsupportedTypeException { return new Integer(sqlCommandBean.executeUpdate( )); } The reason for wrapping the int in an Integer is that only real objects can be saved as JSP scope objects; primitive types are not supported. The and the actions define separate TagExtraInfo classes, named QueryTagExtraInfo and UpdateTagExtraInfo, respectively. They both extend a class called com.ora.jsp.tags.sql.DBTagExtraInfo. The isValid( ) method for the DBTagExtraInfo class makes sure a valid value is specified for the scope attribute. It’s shown in Example 17.20. Example 17.20. The DBTagExtraInfo Class package com.ora.jsp.tags.sql; import javax.servlet.jsp.tagext.*; public class DBTagExtraInfo extends TagExtraInfo { /** * Returns true only if a valid scope value is specified: * page, request, session or application. */ public boolean isValid(TagData data) { boolean isValid = false; String scope = data.getAttributeString(”scope”); if (scope == null || scope.equals(”page”) || scope.equals(”request”) || scope.equals(”session”) || scope.equals(”application”)) { isValid = true; } return isValid; } } The QueryTagExtraInfo and UpdateTagExtraInfo classes implement the getVariableInfo( ) method to tell the container about the result variables they create. Here’s the UpdateTagExtraInfo class: package com.ora.jsp.tags.sql; import javax.servlet.jsp.tagext.*; public class UpdateTagExtraInfo extends DBTagExtraInfo { public VariableInfo[] getVariableInfo(TagData data) { if (data.getAttributeString(”id”) == null) { return new VariableInfo[0]; } else { return new VariableInfo[] { new VariableInfo(data.getAttributeString(”id”), “java.lang.Integer”, true, VariableInfo.AT_END) }; } } } The QueryTagExtraInfo class is almost identical. The only difference is that it sets the class name to com.ora.jsp.sql.Row instead of java.lang.Integer. page 252
Note: If you are looking for inexpensive but high quality provider to host and run your serlvet application check Astra servlet hosting services

Comments are closed.