JavaSercer Pages The action supports the attributes described (Music webhost)

January 30, 2007 on 3:25 am | In Java | No Comments

JavaSercer Pages The action supports the attributes described in Table A.4. Table A.4, Attributes Attribute Name Java Type Request-Time Value Accepted Description Page String Yes Mandatory. A page-relative or context-relative URI path for the resource to forward to. Example: A.3.3 The action adds the value of a bean property, converted to a string, to the response generated by the page. The attributes described in Table A.5 are supported. Table A.5, Attributes Attribute Name Java Type Request-Time Value Accepted Description name String No Mandatory. The name assigned to a bean in one of the JSP scopes. property String No Mandatory. The name of the bean’s property to include in the page. Example: A.3.4 The action includes the response from another JSP page, servlet, or static file in the same web application. The execution of the current page continues after including the response generated by the target resource. If any response content has been buffered when the action is executed, the buffer is flushed first. Even though this behavior can be controlled by the flush attribute, the only valid value in JSP 1.1 is true. This limitation will likely be lifted in a future version of JSP. The URI path information available through the implicit request object reflects the URI path information for the source JSP page even in the target resource. All other request information is also left untouched, so the target resource has access to all the original parameters and headers passed with the request. Additional parameters can be passed to the target resource through elements in the element’s body. The action supports the attributes described in Table A.6. Table A.6, Attributes Attribute Name Java Type Request-Time Value Accepted Description page String Yes Mandatory. A page-relative or context-relative URI path for the resource to include. flush boolean No Mandatory in JSP 1.1 with true as the only accepted value. Example: page 264
Note: If you are looking for good and quality webspace to host and run your java application check professional java hosting services

Php5 web hosting - JavaSercer Pages A.3 Action Elements Actions are executed

January 29, 2007 on 7:32 pm | In Java | No Comments

JavaSercer Pages A.3 Action Elements Actions are executed when the JSP page is requested by a client. They are inserted in a page using XML element syntax, and encapsulate functionality such as input validation using beans, database access, or passing control to another page. The JSP specification defines a few standard action elements, described in this section, and also includes a framework for developing custom action elements. An action element consists of a start tag (optionally with attributes), a body, and an end tag. Other elements can be nested in the body. Here’s an example: If the action element doesn’t have a body, a shorthand notation can be used in which the start tag ends with /> instead of >, as shown by the action in this example. The action element name and attribute names are case-sensitive. Some action attributes accept a request-time attribute value, using the JSP expression syntax: <% String headerPage = currentTemplateDir + "/header.jsp"; %> Plugin tag OBJECT or EMBED not supported by browser. A.3.2 The action passes the request processing control to another JSP page or servlet in the same web application. The execution of the current page is terminated, giving the target resource full control over the request. If any response content has been buffered when the action is executed, the buffer is cleared first. If the response has already been committed (i.e., partly sent to the browser), the forwarding fails with an IllegalStateException. The URI path information available through the implicit request object is adjusted to reflect the URI path information for the target resource. All other request information is left untouched, so the target resource has access to all the original parameters and headers passed with the request. Additional parameters can be passed to the target resource through elements in the element’s body. page 263
Note: If you are looking for cheap and inexpensive provider to host and run your tomcat application check professional tomcat hosting services

JavaSercer Pages A.2 Scripting Elements Scripting elements let (Godaddy web hosting)

January 29, 2007 on 11:39 am | In Java | No Comments

JavaSercer Pages A.2 Scripting Elements Scripting elements let you add small pieces of code to a JSP page, such as an if statement that generates different HTML depending on some condition. The scripting code must be written in the language defined by the page directive. It is executed when the JSP page is requested. A.2.1 Declaration A declaration starts with <%! and ends with %>. The content between the start and the end characters must be a complete, valid declaration in the scripting language defined by the page directive. The JSP implicit variables are not visible in a declaration element. A declaration can be used to declare a scripting language variable or method. When the scripting language is Java, a variable declared by a declaration element ends up as an instance variable in the JSP page implementation class. It is therefore visible to parallel threads (requests) processing the page, and needs to be handled in a thread-safe manner. A thread-safe alternative is to declare variables within a scriptlet element instead. It then becomes a local variable of the method in the page implementation class used to process each request, and is not shared by parallel threads. Example: <%! int globalCounter = 0; %> A.2.2 Expression An expression starts with <%= and ends with %>. The content between the start and the end characters must be a complete, valid expression in the scripting language defined by the page directive that results in or can be converted to a string. All JSP implicit variables are visible in an expression element. Example: <%= globalCounter++ %> A.2.3 Scriptlet A scriptlet starts with <% and ends with %>. The content between the start and the end characters must be a code fragment in the scripting language defined by the page directive. Scriptlet code fragments are combined with code for sending the template data between them to the browser. The combination of all scriptlets in a page must form valid scripting language statements. All JSP implicit variables are visible in a scripting element. Example: <% java.util Date clock = new java.util.Date( ) %> <% if (clock.getHours( ) < 12) { %> Good morning! <% } else if (clock.getHours( ) < 17) { %> Good day! <% } else { %> Good evening! <% } %> page 262
Quick Hint: If you are looking for cheap and reliable provider to host and run your servlet application check Vision servlet hosting plans

JavaSercer Pages import No default A Java import (Video web hosting)

January 29, 2007 on 6:15 am | In Java | No Comments

JavaSercer Pages import No default A Java import declaration, i.e., a comma-separated list of fully qualified class names or package names followed by .* (for all public classes in the package). info No default Text that a web container may use as a description of the page in its administration user interface. isErrorPage false Set to true for a page that is used as an error page, to make the implicit exception variable available to scripting elements. Use false for regular JSP pages. isThreadSafe true Set to true if the container is allowed to run multiple threads through the page (i.e., lets the page serve parallel requests). If set to false, the container serializes all requests for the page. It may also use a pool of page implementation class instances to serve more than one request at a time. The recommendation is to always use true, and handle multithread issues by avoiding JSP declarations and ensuring that all objects used by the page are thread-safe. language java Defines the scripting language used in the page. session true Set to true if the page should participate in a user session. If set to false, the implicit session variable is not available to scripting elements in the page. A translation unit (the JSP source file and any files included via the include directive) can contain more than one page directive, as long as there is only one occurrence of an attribute, with the exception of the import attribute. If multiple import attribute values are used, they are combined into one list of import definitions. Example: <%@ page language="java" contentType="text/html;charset=Shift_JIS"%> <%@ page import="java.util.*, java.text.*" %> <%@ page import="java.sql.Date" %> A.1.3 taglib Directive Declares a tag library, containing custom actions, that is used in the page. The taglib directive supports the attributes described in Table A.3. Table A.3, taglib Directive Attributes Attribute Name Default Description prefix No default Mandatory. The prefix to use in the action element names for all actions in the library. uri No default Mandatory. Either a symbolic name for the tag library defined in the web.xml file for the application, or a page-relative or context-relative URI path for the library’s TLD file or JAR file. Example: <%@ taglib uri="/orataglib" prefix="ora" %> page 261
Note: If you are looking for inexpensive but high quality provider to host and run your serlvet application check Astra servlet hosting services

JavaSercer Pages Appendix A. JSP Elements (System web hosting) Syntax Reference

January 29, 2007 on 12:25 am | In Java | No Comments

JavaSercer Pages Appendix A. JSP Elements Syntax Reference JSP defines three types of elements: directives, scripting elements, and action elements. In addition, you can define your own custom actions. This appendix contains descriptions of all JSP elements as well as the general syntax rules for custom actions. A.1 Directive Elements Directive elements are used to specify information about the page itself, especially information that doesn’t differ between requests for the page. The general directive syntax is: <%@ directiveName attr1="value1" attr2="value2" %> The attribute values can be enclosed with single quotes instead of double quotes. The directive name and all attribute names are case-sensitive. A.1.1 include Directive The include directive includes a static file, merging its content with the including page before the combined result is converted to a JSP page implementation class. The include directive supports the attribute described in Table A.1. Table A.1, include Directive Attribute Attribute Name Default Description file No default A page-relative or context-relative URI path for the file to include A page can contain multiple include directives. The including page and all included pages together form what is called a JSP translation unit. Example: <%@ include file="header.html" %> A.1.2 page Directive The page directive defines page-dependent attributes, such as scripting language, error page, and buffering requirements. It supports the attributes described in Table A.2. Table A.2, page Directive Attributes Attribute Name Default Description autoFlush true Set to true if the page buffer should be flushed automatically when it’s full, or to false if an exception should be thrown when it’s full. buffer 8kb Specifies the buffer size for the page. The value must be expressed as the size in kilobytes followed by kb, or be the keyword none to disable buffering. contentType text/html The MIME type for the response generated by the page, and optionally the charset for the source page as well as the response; e.g., text/html;charset=Shift_JIS. errorPage No default A page-relative or context-relative URI path for the JSP page to forward to if an exception is thrown by code in the page. extends No default The fully qualified name of a Java class that the generated JSP page implementation class extends. The class must implement the JspPage or HttpJspPage interface in the javax.servlet.jsp package. Note that the recommendation is to not use this attribute. Specifying your own superclass restricts the JSP container’s ability to provide a specialized, high-performance superclass. page 260
Hint: If you are looking for good and high quality web space to host and run your java application check Vision java web hosting services

JavaSercer Pages In the doEndTag( ) method, all (Postgres hosting)

January 28, 2007 on 5:35 pm | In Java | No Comments

JavaSercer Pages In the doEndTag( ) method, all request parameters with information about the employee are first retrieved. If a parameter is missing, an exception is thrown. Then an SQLCommandBean instance is created, the DataSource object fetched from the application scope, and a Connection created and provided to the bean. The bean is used to execute a SELECT statement to find out if the specified employee is already defined in the database. If not, the bean is used to execute an INSERT statement with all the information provided through the request parameters. Otherwise, the bean is used to execute an UPDATE statement. The tag handler class described here is intended only to show how you can use the database access classes to implement your own custom actions. The tag handler class could be improved in several ways. For instance, it could provide default values for missing parameters, such as the current date for a missing employment date, or an email address based on the employee’s first and last names if the email address is missing. You could also use a bean as input to the action instead of reading request parameters directly. This would allow the bean to be used as described in Chapter 6, and Chapter 8, to capture and validate the user input until all information is valid, and then pass it on to the custom action for permanent storage of the information in a database. page 259
Hint: If you are looking for high quality webhost to host and run your jsp application check Vision web hosting jsp services

JavaSercer Pages Vector values = new Vector( );

January 28, 2007 on 10:21 am | In Java | No Comments

JavaSercer Pages Vector values = new Vector( ); values.addElement(new StringValue(userName)); sqlCommandBean.setSqlValue(sqlValue); sqlCommandBean.setValues(values); Vector rows = sqlCommandBean.executeQuery( ); // Create values for insert/update values.removeAllElements( ); values.addElement(new StringValue(password)); values.addElement(new StringValue(firstName)); values.addElement(new StringValue(lastName)); values.addElement(new StringValue(dept)); values.addElement(new DateValue( new Date(StringFormat.toDate(empDate, “yyyy-MM-dd”).getTime( )))); values.addElement(new StringValue(emailAddr)); values.addElement(new TimestampValue( new Timestamp(System.currentTimeMillis( )))); values.addElement(new StringValue(userName)); if (rows.size( ) == 0) { // New user. Insert StringBuffer sb = new StringBuffer( ); sb.append(”INSERT INTO Employee “). append(”(Password, FirstName, LastName, Dept, “). append(”EmpDate, EmailAddr, ModDate, UserName) “). append(”VALUES(?, ?, ?, ?, ?, ?, ?, ?)”); sqlCommandBean.setSqlValue(sb.toString( )); } else { // Existing user. Update StringBuffer sb = new StringBuffer( ); sb.append(”UPDATE Employee “). append(”SET Password = ?, FirstName = ?, “). append(”LastName = ?, Dept = ?, EmpDate = ?, “). append(”EmailAddr = ?, ModDate = ? “). append(”WHERE UserName = ?”); sqlCommandBean.setSqlValue(sb.toString( )); } sqlCommandBean.executeUpdate( ); } catch (SQLException e) { throw new JspException(”SQL error: ” + e.getMessage( )); } catch (UnsupportedTypeException e) { throw new JspException(”Query result error: ” + e.getMessage( )); } catch (ParseException e) { throw new JspException(”Invalid empDate format: ” + e.getMessage( )); } finally { try { if (conn != null) { conn.close( ); } } catch (SQLException e) { // Ignore } } return EVAL_PAGE; } public void release( ) { dataSourceName = null; super.release( ); } } This tag handler has one property, named dataSource. It’s marked as required in the TLD for the tag, so it will always be set: … saveEmployeeInfo com.mycompany.tags.SaveEmployeeInfoTag empty dataSource true … page 258
Note: If you are looking for inexpensive but high quality provider to host and run your serlvet application check Astra servlet hosting services

JavaSercer Pages 17.4 Developing Application-Specific Database Components The (Top web hosting companies)

January 28, 2007 on 5:21 am | In Java | No Comments

JavaSercer Pages 17.4 Developing Application-Specific Database Components The classes described in this chapter can also be used for application-specific components that access a database. Chapter 15 includes one example of an application-specific bean, the EmployeeRegisterBean, that uses the SQLCommandBean to execute its SQL statements. You can also use these classes in your application-specific custom actions. One example is the custom action that’s mentioned in Chapter 9 as an alternative to the generic database actions for inserting or updating employee information: <%@ page language="java" contentType="text/html" %> <%@ taglib uri="/orataglib" prefix="ora" %> <%@ taglib uri="/mytaglib" prefix="myLib" %> <%-- Get the new or updated data from the database --%> SELECT * FROM Employee WHERE UserName = ? <%-- Redirect to the confirmation page --%> Example 17.27 shows one way to implement this custom action. Example 17.27. SaveEmployeeInfoTag Class package com.mycompany.tags; import java.sql.*; import java.text.*; import java.util.Vector; import javax.sql.*; import javax.servlet.*; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import com.ora.jsp.sql.*; import com.ora.jsp.sql.value.*; import com.ora.jsp.util.*; public class SaveEmployeeInfoTag extends TagSupport { private String dataSourceName; public void setDataSource(String dataSourceName) { this.dataSourceName = dataSourceName; } public int doEndTag( ) throws JspException { // Get all request parameters ServletRequest request = pageContext.getRequest( ); String userName = request.getParameter(”userName”); String password = request.getParameter(”password”); String firstName = request.getParameter(”firstName”); String lastName = request.getParameter(”lastName”); String dept = request.getParameter(”dept”); String empDate = request.getParameter(”empDate”); String emailAddr = request.getParameter(”emailAddr”); if (userName == null || password == null || firstName == null || lastName == null || dept == null || empDate == null || emailAddr == null) { throw new JspException(”Missing a mandatory parameter”); } SQLCommandBean sqlCommandBean = new SQLCommandBean( ); DataSource dataSource = (DataSource) pageContext.getAttribute(dataSourceName, PageContext.APPLICATION_SCOPE); if (dataSource == null) { throw new JspException(”The data source ” + dataSource + ” is not found in the application scope”); } Connection conn = null; try { conn = dataSource.getConnection( ); sqlCommandBean.setConnection(conn); // See if the user exists String sqlValue = “SELECT * FROM Employee WHERE UserName = ?”; page 257

Hint: This post is supported by Gama web hosting php mysql provider

Java web hosting - JavaSercer Pages finally { try { if (isPartOfTransaction

January 27, 2007 on 10:17 pm | In Java | No Comments

JavaSercer Pages finally { try { if (isPartOfTransaction && isExceptionThrown) { // Reset auto commit in case the connection is // pooled before it’s returned to the pool by close conn.setAutoCommit(true); conn.close( ); } else if (!isPartOfTransaction) { // If we’re not part of a transaction, the // connection is in auto commit mode so we only // close it conn.close( ); } } catch (SQLException e) { e.printStackTrace(System.err); } } // Save the result with the specified id in the specified scope if (id != null) { pageContext.setAttribute(id, result, scope); } return EVAL_PAGE; } The interesting code is in the catch and finally clauses of the try block. If the execution of the SQL statement causes an exception to be thrown, the transaction is rolled back and a JspException is thrown. This aborts the processing of the rest of the page and informs the user about the error. A boolean flag is also set to be able to handle this case in the finally clause. The finally clause is executed whether or not an exception is thrown. If this action is part of a transaction and an exception is thrown by the execute( ) method, the Connection is returned to the pool by calling the close( ) method after auto commit is turned on again to reset it to its default state. If the action is not part of a transaction, there’s no need to reset the auto commit since it has never been changed; the Connection is just returned to the pool by calling the close( ) method. If the action is part of a transaction and no exception is thrown, the result is saved in the specified scope, and processing continues with the next nested database action. Note that the Connection is not closed in this case, as the same Connection must be used for all SQL statements in the transaction. If all actions execute successfully, the TransactionTag ’s doEndTag( ), shown in Example 17.26, is invoked. Example 17.26. The TransactionTag’s doEndTag( ) Method public int doEndTag( ) throws JspException { try { conn.commit( ); conn.setAutoCommit(true); conn.close( ); } catch (SQLException e) { throw new JspException(”SQL error: ” + e.getMessage( )); } return EVAL_PAGE; } The doEndTag( ) method commits the transaction, resets the auto commit for the Connection, and returns the Connection to the pool by calling the close( ) method. page 256
Note: If you are looking for cheapest and affordable webspace to host and run your servlet application check Astra j2ee hosting services

Ssh hosting - JavaSercer Pages The package scope getConnection( ) method,

January 27, 2007 on 4:09 pm | In Java | No Comments

JavaSercer Pages The package scope getConnection( ) method, also shown in Example 17.23, is used by the tag handlers for the and actions. To see how it’s used, let’s look at the method with the same name in the DBTag class that we skipped earlier. The DBTag ’s getConnection( ) method is shown in Example 17.24. Example 17.24. The DBTag’s getConnection( ) Method private Connection getConnection( ) throws JspException { Connection conn = null; TransactionTag transactionTag = (TransactionTag) findAncestorWithClass(this, TransactionTag.class); if (transactionTag != null) { conn = transactionTag.getConnection( ); isPartOfTransaction = true; if (dataSourceName != null) { throw new JspException(”A dataSource must not be ” + “specified when the action is part of a ” + “transaction”); } } else { DataSource dataSource = (DataSource) pageContext.getAttribute(dataSourceName, PageContext.APPLICATION_SCOPE); if (dataSource == null) { throw new JspException(”dataSource ” + dataSourceName + ” not found”); } try { conn = dataSource.getConnection( ); } catch (SQLException e) { throw new JspException(”SQL error: ” + e.getMessage( )); } } return conn; } The findAncestorWithClass( ) is used to find out whether or not the action is nested in the body of an tag. If a TransactionTag is found, the action is part of a transaction, so the TransactionTag’s get-Connection( ) is used to retrieve the shared Connection, and a boolean flag is set to remember that the action is part of a transaction. If a parent tag handler is not found, the action is not part of a transaction. In this case, the DBTag’s dataSource property value is used instead to locate the DataSource in the application scope and get a Connection. The doEndTag( ) method in the DBTag class contains some details related to database transactions that we also skipped earlier. Let’s revisit this method, shown in Example 17.25. Example 17.25. The DBTag’s doEndTag( ) Method public int doEndTag( ) throws JspException { Connection conn = getConnection( ); sqlCommandBean.setConnection(conn); sqlCommandBean.setSqlValue(sqlValue); sqlCommandBean.setValues(values); Object result = null; try { result = execute(sqlCommandBean); } catch (SQLException e) { try { isExceptionThrown = true; conn.rollback( ); } catch (SQLException se) { // Ignore, probably a result of the main exception } throw new JspException(”SQL error: ” + e.getMessage( )); } catch (UnsupportedTypeException e) { try { isExceptionThrown = true; conn.rollback( ); } catch (SQLException se) { // Ignore, probably caused by the main exception } throw new JspException(”Query result error: ” + e.getMessage( )); } page 255
Hint: If you are looking for high quality webhost to host and run your jsp application check Vision web hosting jsp services

« Previous PageNext Page »