Archive for November, 2007

However, with nontrivial web applications, (My web server) this is not

Thursday, November 8th, 2007

However, with nontrivial web applications, this is not the case logging is just as critical there as it is in an enterprise application. System Versus Application Logging Log messages can be arbitrarily broken down into two categories: system messages and application messages. System messages have to do with the internal operation of the application, rather than something specific to a user or data for example, a system message might indicate that the application is unable to send an email because the SMTP host is not responding. On the other hand, an application message might indicate that the user “Jane Doe” tried to submit a purchase order that was above her company’s credit limit. The system message in the first case might be logged with a priority of “error,” whereas the application message might only get a priority of “info.” We can then set up the logging environment so that “error” messages generate an email or a pager message to the system administrators for immediate attention, while “info” messages go into a file for later auditing. The different types and categories of log messages are typically used for different purposes across organizations. Although many applications may log messages with the priority of “error,” what’s an error to one organization may just be a warning to another. There’s not a great deal of consistency across organizations, and there may never be organizations have different priorities, and what’s critical to one may not necessarily be critical to another. In this chapter, we will generalize the discussion of system versus application messages. Because views of what’s considered an error differ, there’s no general way to specify what’s an error, a warning, or just general information for your particular application. That’s a decision that you, your development team, and your product-management group will have to make. We’ll keep our discussion at a higher level and not focus on these issues. 15.2 Using the Servlet Container for Logging The Servlet specification requires that every servlet container allow developers to log events to the container log file. Although the name and location of the log file are container-dependent, the manner in which these events are logged is dictated by the specification and is portable across web containers. The javax.servlet.ServletContextclass contains two methods that can be used for logging messages to the container’s log: public void log( String msg ); public void log( String msg, Throwable throwable ); You can use either of these methods by obtaining the ServletContext and passing the appropriate arguments. Example 15-1 illustrates how this can be done using a Struts Action. Example 15-1. The LoginAction using the ServletContext to log messages public class LoginAction extends StorefrontBaseAction { public ActionForward execute( ActionMapping mapping,
You want to have a cheap webhost for your apache application, then check apache web hosting services.

As with (Sri lanka web server) regular Java resource bundles, you should

Wednesday, November 7th, 2007

As with regular Java resource bundles, you should always provide a base definition that is used when no locale is provided or when an unsupported locale is used. No language or country suffix is appended to the name of the Tiles base definition file. Once you have created the locale-specific definition files and placed them in the WEB-INF directory, the only other necessary step is to ensure that a Locale is stored in the user’s HttpSession. The Tiles framework depends on the same Locale instance that Struts uses to determine which definition file to use. You will need to ensure that the Struts framework is storing the user’s Locale in the session. This is accomplished by setting the locale attribute to true in the controller element. See Section 4.7.2 for more information on the controller element. That’s all there is to it. Note that you should still rely on the Struts resource bundle for locale-sensitive resources such as text, messages, and images. The I18N support in Tiles should be used for differences in layout based on the locale. Struts and Tiles work very well together to provide complete I18N support. Chapter 15. Logging in a Struts Application As dedicated and knowledgeable Java programmers, we always want to believe that the software we create will stand up to the utmost scrutiny. However, as human beings, we’ll all fallible, so it’s never a good practice to believe that our software contains no defects. The important thing is to use every means available to try to eliminate the defects, or at least reduce them to an acceptable amount. Generating log messages that tell you what the application is doing can help you locate any defects that are present in your software. However, logging is important for other reasons as well. For example, security and auditing might depend on logging to provide information to the system administrators about what the authorized and, more importantly, unauthorized users of the application are doing. By providing real-time information about potential security attacks on the application, logging can give a much-needed edge to the system administrators and allow for quicker reactions to attacks. This chapter takes a close look at how the use of logging in your Struts application can help you identify defects before the application gets into production, or, if your software is already being used in production, how logging can help you to quickly identify problems with the software and arrive at solutions. 15.1 Logging in a Web Application The importance of logging has been evident to experienced developers for many years. Arguably, logging can be as important a part of your framework as exception handling or even security, both of which may rely on logging functionality to help carry out their responsibilities. Without logging in an application, maintenance can become a nightmare for the developers. We all know that all “real” applications periodically go through maintenance cycles. Still, you may wonder whether logging in web applications is as necessary and important as logging in other types of applications. Because web applications can sometimes be smaller and less complex than their enterprise counterparts, you might think that logging is less important in these applications.
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Jetty web server - 14.5.4 Using Definitions as Forwards in Struts Tiles

Tuesday, November 6th, 2007

14.5.4 Using Definitions as Forwards in Struts Tiles definitions can also be used as Struts forwards, instead of actual URLs. To use definitions in this manner, you first create the definitions:

This fragment shows two definitions, the standard default definition and a second one that defines the layout for a “superuser.” A superuser might be someone that frequents the site and places many orders, and such a user might be given more options on the menu bar to facilitate faster ordering. In the Struts configuration file, we need to define the forwards that use these definitions: You can then use the Super_Success forward to send the user to the storefront.superuser.main definition just as you would for any other forward. 14.6 Internationalization Support with Tiles Although the Struts framework provides certain I18N capabilities that can be used with Tiles, Tiles also provides the ability to select a particular tile based on the user’s locale. To support this feature in your application, you need to create a different Tiles definition file for each locale that you need to support. For example, if you need to support a set of definitions for the U.S. locale and a separate set for the German locale, you must create two separate definition files: tiles-tutorial-defs_en.xml tiles-tutorial-defs_de.xml The suffix naming conventions follow the ones set by the java.util.ResourceBundle, which is also used by the resource bundles for Struts. When a request for a definition is made, the correct definition is determined by the included locale.
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Web servers - but in the XML definition, you use the

Monday, November 5th, 2007

but in the XML definition, you use the put element:
Make sure that you don’t get these two confused, as this can be a difficult bug to track down. Each definition should have a unique name. JSP tags and pages use the name to retrieve the definition. It can’t be used as a URL, however; it’s only a logical name for the definition. 14.5.3 Extending Tile Definitions One of the most powerful features of tile definitions is the ability to create new definitions by extending existing ones. All attributes and properties of the parent definition are inherited, and you can override any attribute or property. To extend a definition, add the extends attribute. Example 14-9 shows an example of a definition named storefront.custom extending the storefront.default definition. Example 14-9. Definitions can extend other definitions

In Example 14-9, all of the attributes in the storefront.default definition are inherited. However, the storefront.customer definition overrides the value for the copyrightattribute with an alternate copyright page. This is a very powerful feature. If you have multiple child definitions all extending a root definition, changing a value in the root definition changes it for all the children. Thus, you can change the layout in the root definition and have it changed for all child definitions.
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

With this approach, the tile components (Web host sites) have to

Monday, November 5th, 2007

With this approach, the tile components have to insert only the page-specific content. Compare Example 14-7 to Example 14-5. Notice that the signin.jsp file using the definition needs to provide only the page-specific content, the sign-body.jsp file. 14.5.2 Declaring Definitions in a Configuration File You also have the option of declaring definitions in a centralized XML file. Whether you use the JSP or the XML alternative really depends on your requirements. With the XML approach, you won’t need to use the include directive shown earlier. 14.5.2.1 Creating a definition configuration file To use the XML approach, create an XML file that follows the syntax of the tiles-config.dtd file. The definition XML file should be placed in the WEB-INF directory, as with the other application metainformation. The DTD should also be placed in the WEB-INF directory. Example 14-8 shows an example of a definition XML file. Example 14-8. The Storefront definition XML file
There’s not much difference between the definition format specified in the JSP file in Example 14-6 and the XML file in Example 14-8. The XML file uses a slightly different syntax, but it’s still very similar. The two formats are just similar enough to cause problems. Notice that in the JSP definition, you use the put tag:
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.

My web server - Definitions can be declared in a JSP page

Sunday, November 4th, 2007

Definitions can be declared in a JSP page or an XML file. Either way, you should strive to keep the definitions in a central place. If you are planning on using a JSP page to specify your definitions, put all the definitions for your application in a single page. Don’t spread your definitions throughout your site, as that will only make maintenance more difficult. 14.5.1 Declaring Definitions in a JSP Page As was previously mentioned, there are two locations in which you can specify definitions: a JSP page or an XML file. We’ll discuss the JSP page approach first. To use the JSP approach, create a JSP page and declare all of your definitions in that file. For the Storefront application, we’ve created a file called storefront-defs.jsp and put the default definition in it, as Example 14-6 shows. Example 14-6. Declaring tiles definitions in a JSP page <%@ taglib uri="/WEB-INF/tiles.tld" prefix="tiles" %> The definition in Example 14-6 uses the same layout tile used earlier. The common files that were spread through the various tiles are now located in the definition file. This makes changing their values much easier. For instance, if we wanted to specify a different copyright page, the only place to change it would be in the definition file; we would not have to modify every JSP page. The definition tag syntax looks very similar to the syntax for the insert tags shown earlier. We just need to provide an id attribute and switch the path attribute to the page attribute. Also, the default scope for the definition tag is page. It was set to request scope here to give it a little broader scope. To take advantage of the definition, the tile components need to be able to access it. Because we have given the definition request scope and it will exist only for the lifetime of a request, we need a way to include the definition in the various JSP pages. Fortunately, we already know how to include a JSP page in another page using the JSP include directive. Example 14-7 shows what the signin.jsp page looks like using the JSP definition file. Example 14-7. The signin.jsp page using a tile definition <%@ taglib uri="/WEB-INF/tiles.tld" prefix="tiles" %> <%@include file="../common/storefront-defs.jsp" %>
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Table 14-10. Attributes for the importAttribute tag Attribute (Email web hosting)

Saturday, November 3rd, 2007

Table 14-10. Attributes for the importAttribute tag Attribute name Description ignore If this attribute is set to true and the attribute specified by the name does not exist, simply return without error. The default value is false, which will cause a runtime exception to be thrown. name The tile’s attribute name. If not specified, all attributes are imported. scope The scope into which the attribute is imported. Defaults to “page”. 14.4.10 The initComponentDefinitions Tag The initComponentDefinitions tag initializes the definitions factory. Table 14-11 lists the attributes for the tag. Table 14-11. Attributes for the initComponentDefinitions tag Attribute name Description classname If specified, the classname attribute of the factory to create and initialize. file The definition file’s name. This attribute is required . 14.5 Using Definitions The tiles shown so far add value to an application because they organize the layout of a page in a single resource, the layout JSP page. This can save development time and, more importantly, the time it takes to change the layout for an application. However, there is a problem with the approach used in the Storefront application shown earlier. In each of the non-layout tiles, there is redundant code that specifies what content to use for the header, menubar, and copyright content the same attributes are being passed in every page. This may not always be the case, but in general, these values will be constant throughout an application. For instance, the same copyright is typically shown on every page. It’s redundant to have to specify these in every tile. Ideally, we could declare these attributes in one place, and the tiles could include just the page-specific attributes where needed. Tiles definitions provide just such functionality. A definition allows you to statically specify the attributes that are used by a template, which in turn allows you to specify only the page-specific attributes in your tiles. Definitions enable you to: Screen definitions Centralize declaration of page description Avoid repetitive declaration of nearly identical pages (by using definition inheritance) Avoid creation of intermediate components used to pass parameters Specify the name of a definition as a forward in the Struts configuration file Specify the name of a definition as component parameters Overload definition attributes Use a different copy of a component, depending on the locale (I18N) Use a different copy of a component, depending on a key (this might be used to show different layouts depending on the client type)
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

ignored. 14.4.7 The getAsString Tag The getAsString tag

Friday, November 2nd, 2007

ignored. 14.4.7 The getAsString Tag The getAsString tag retrieves the value of the specified tile attribute property and renders it to the current JspWriter as a String. The usual toString( ) conversion is applied to the value. If the named value is not found, a JSPException will be thrown. Table 14-8 lists the attributes for the getAsString tag. Table 14-8. Attributes for the getAsString tag Attribute name Description ignore If this attribute is set to true and the attribute specified by the name does not exist, simply return without writing anything. The default value is false, which will cause a runtime exception to be thrown. name The attribute name. This attribute is required. role If the user is in the specified role, the tag is taken into account; otherwise, the tag is ignored. 14.4.8 The useAttribute Tag The useAttribute tag declares a Java variable and an attribute in the specified scope, using the tile’s attribute value. The variable and attribute will have the name specified by id, or the original name if not specified. Table 14-9 lists the attributes for the useAttribute tag. Table 14-9. Attributes for the useAttribute tag Attribute name Description classname The class of the declared variable. id The declared attribute and variable name. ignore If this attribute is set to true and the attribute specified by the name does not exist, simply return without error. The default value is false, which will cause a runtime exception to be thrown. name The tile’s attribute name. This attribute is required. scope The scope of the declared attribute. Defaults to “page”. 14.4.9 The importAttribute Tag The importAttribute tag imports the attribute from the tile to the requested scope. The name and scope attributes are optional. If not specified, all tile attributes are imported in page scope. Once imported, an attribute can be used like any other bean from the JSP context. Table 14-10 lists the attributes for the importAttribute tag.
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

14.4.5 The add Tag The add tag adds (Web hosting servers)

Thursday, November 1st, 2007

14.4.5 The add Tag The add tag adds an element to the surrounding list. This tag can be used only inside the putListtag. The value can come from a direct assignment (value=”aValue”) or from a bean. One of valueor beanName must be specified. Table 14-6 lists the attributes for the add tag. Table 14-6. Attributes for the add tag Attribute name Description beanName The name of the bean used to retrieve the value. The bean is retrieved from the specified context, if any. Otherwise, the pageContext.findAttribute( )method is used. If beanProperty is specified, retrieve the value from the corresponding bean property. beanPropertyThe bean property name. If specified, the value is retrieved from this property. beanScope The scope used to search for the bean. If not specified, the pageContext.findAttribute( )method is used. The scope can be any JSP scope, “component”, or “template”. In the two latter cases, the bean is searched in the tile/component/template context. content The value is the same as the value attribute. This attribute was added for compatibility with the JSP template tags. direct How the content is handled: truemeans content is printed directly; false means content is included. false is the default. role If the user is in the specified role, the tag is taken into account; otherwise, the tag is ignored (skipped). The role isn’t taken into account if the add tag is used in a definition. type The content type: “string”, “page”, “template”, or “definition”. If the type attribute is not specified, content is untyped, unless it comes from a typed bean. value The value to be added. Can be a Stringor Object. 14.4.6 The get Tag The gettag retrieves content from the tile context and includes it in the page. Table 14-7 lists the attributes for the get tag. Table 14-7. Attributes for the get tag Attribute name Description flush trueor false. If true, the current page output stream is flushed before tile insertion. ignore If this attribute is set to true and the attribute specified by the name does not exist, simply return without writing anything. The default value is false, which will cause a runtime exception to be thrown. name The name of the content to get from the tile scope. This attribute is required. role If the user is in the specified role, the tag is taken into account; otherwise, the tag is
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.