Web Hosting Java, JSP, Tomcat 6, J2EE, Servlets, Struts, Jboss
Adsl web hosting - JavaSercer Pages 5.1.4 Accessing JavaBean Properties The bean’s
November 30, 2006 on 9:09 pm | In Java | No Comments JavaSercer Pages 5.1.4 Accessing JavaBean Properties The bean’s data is represented by its properties . If you’re a page author charged with developing a JSP page to display the content represented by a bean, you first need to know the names of all the bean’s properties. This information should be available from the Java programmers on the team or from a third-party source. In this example, we use a standard Java class named java.util.Date as a bean with properties representing date and time information. Table 5.1 describes the properties used in this example. (If you’re not a programmer, don’t worry about the Java Type and Access columns at this point.) Table 5.1, Properties for java.util.Date Property Name Java Type Access Description date int read The day of the month as a number between 1 and 31 hours int read The hour as a number between 0 (midnight) and 23 minutes int read The number of minutes past the hour as a number between 0 and 59 month int read The month as a number from 0 to 11 year int read The current year minus 1900 Once you have created a bean and given it a name, you can retrieve the values of the bean’s properties in the response page with another JSP standard action,
Hint: If you are looking for very good and affordable webspace to host and run your tomcat hosting application check Virtualwebstudio tomcat web hosting provider
Servlets hosting - JavaSercer Pages 5.1.3 Using JavaBeans There is also
November 30, 2006 on 1:04 pm | In Java | No Comments JavaSercer Pages 5.1.3 Using JavaBeans There is also some dynamic content in this example. Step back a moment and think about the type of dynamic content you see on the Web every day. Common examples might be a list of web sites matching a search criteria on a search engine site, the content of a shopping cart on an e-commerce site, a personalized news page, or messages on a bulletin board. Dynamic content is content generated by some server process, for instance the result of a database query. Before it is sent to the browser, the dynamic content needs to be combined with regular HTML elements into a page with the right layout, navigation bars, the company logo, and so forth. In a JSP page, the regular HTML is the template text described earlier. The result of the server processing - the dynamic content - is commonly represented by a JavaBeans component. A JavaBeans component, or just a bean for short, is a Java class that follows certain coding conventions, so it can be used by tools as a component in a larger application. In this chapter, we discuss only how to use a bean, not how to develop one. (If you’re a programmer and not already familiar with JavaBeans, you may want to skip ahead to Chapter 15, to learn about these coding conventions.) A bean is often used in JSP as the container for the dynamic content to be displayed by a web page. Typically, a bean represents something specific, such as a person, a product, or a shopping order. A bean is always created by a server process and given to the JSP page. The page then uses JSP elements to insert the bean’s data into the HTML template text. The type of element used to access a bean in a page is called a JSP action element. JSP action elements are executed when a JSP page is requested (this is called the request processing phase, as you may recall from Chapter 3). In other words, JSP actions represent dynamic actions that take place at runtime, as opposed to JSP directives, which are used only during the translation phase (when the JSP page is turned into Java servlet code). JSP defines a number of standard actions and also specifies how you can develop custom actions. For both standard and custom action elements, use the following notation:
Hint: If you are looking for high quality and reliable webspace provider to host and run your jsp hosting application check Virtualwebstudio jsp web hosting provider
JavaSercer Pages 5.1.1 Using JSP Directives The first
November 30, 2006 on 7:41 am | In Java | No CommentsJavaSercer Pages 5.1.1 Using JSP Directives The first line in Example 5.1 is a JSP directive element. Directives are used to specify attributes of the page itself, primarily those that affect how the page is converted into a Java servlet. There are three JSP directives: page, include, and taglib. In this example, we’re using only the page directive. We’ll see the others later. JSP pages typically start with a page directive that specifies the scripting language and the content type for the page: <%@ page language="java" contentType="text/html" %> A JSP directive element starts with a directive-start identifier (<%@ ) followed by the directive name (e.g., page) and directive attributes, and ends with %>. A directive contains one or more attribute name/value pairs (e.g., language=”java”). Note that JSP element and attribute names are case-sensitive, and in most cases the same is true for attribute values. For instance, the language attribute value must be java, not Java. All attribute values must also be enclosed in single or double quotes. The page directive has many possible attributes. In Example 5.1, two of them are used: language and contentType. The language attribute specifies the scripting language used in the page. The JSP reference implementation (the Tomcat server) supports only Java as a scripting language.3 java is also the default value for the language attribute, but for clarity you may still want to specify it. Other JSP implementations support other languages besides Java, and hence allow other values for the language attribute. For instance, both JRun (http://www.allaire.com) and Resin (http://www.caucho.com) support JavaScript in addition to Java. The contentType attribute specifies the type of content the page produces. The most common values are text/html for HTML content and text/plain for preformatted, plain text. But you can also specify other types, such as text/xml for browsers that support XML or text/vnd.wap.wml for devices like cellular phones and PDAs that have built-in Wireless Markup Language (WML) browsers. If the content generated by the page includes characters requiring a charset other than ISO-8859-1 (commonly known as Latin-1), you need to specify that charset with the contentType attribute. We’ll look at the details of charsets in Chapter 11. 5.1.2 Using Template Text Besides JSP elements, notice that the page shown in Example 5.1 contains mostly regular HTML: …
… The current time at the server is:- Date: …
- Month: …
- Year: …
- Hours: …
- Minutes: …
In JSP parlance, this is called template text. Everything that’s not a JSP element, such as a directive, action, or scripting element, is template text. Template text is sent to the browser as-is. This means you can use JSP to generate any type of text-based output, such as XML, WML, or even plain text. The JSP container doesn’t care what the template text is. 3 In fact, Java is the only scripting language formally supported in the JSP specification, but the specification leaves room for other languages to be supported. page 44
Note: If you are looking for cheap and inexpensive provider to host and run your tomcat application check Actions tomcat hosting services
JavaSercer Pages (Clan hosting) Figure 5.1. JSP book examples main
November 30, 2006 on 2:26 am | In Java | No Comments JavaSercer Pages Figure 5.1. JSP book examples main page Figure 5.2. Current Date/Time JSP page example Notice that the month seems to be off by one and the year is displayed as 100. That’s because the java.util.Date class we use here numbers months from to 11, so January is 0, February is 1, and so on, and it reports year as the current year minus 1900. That’s just the way this example works. As you will see later, there are much better ways to display dates. The page shown in Example 5.1 contains both regular HTML elements and JSP elements. The HTML elements are used as-is, defining the layout of the page. If you use the View Source function in your browser, you notice that none of the JSP elements are visible in the page source. That’s because the JSP elements are processed by the server when the page is requested, and only the resulting output is sent to the browser. To see the unprocessed JSP page in a separate window, click on the source link for the date.jsp file in the book examples main page. The source link uses a special servlet to send the JSP page as-is to the browser instead of letting the server process it. This makes it easier for you to compare the source page and the processed result. Let’s look at each piece of Example 5.1 in detail. page 43
Note: If you are looking for inexpensive but high quality provider to host and run your jsp application check Astra jsp hosting services
Secure web hosting - JavaSercer Pages Chapter 5. Generating Dynamic Content JSP
November 29, 2006 on 6:34 pm | In Java | No CommentsJavaSercer Pages Chapter 5. Generating Dynamic Content JSP is all about generating dynamic content: content that differs based on user input, time of day, the state of an external system, or any other runtime conditions. JSP provides you with lots of tools for generating this content. In this java blog, you will learn about all of them - standard actions, custom actions, JavaBeans, and scripting elements. Before we do that, however, let’s start with a few simple examples to get a feel for how the basic JSP elements work. In this chapter, we develop a page for displaying the current date and time, and look at the JSP directive element and how to use JavaBeans in a JSP page along the way. Next, we look at how to process user input in your JSP pages and make sure it has the appropriate format. We also look at how you can convert special characters in the output, so they don’t confuse the browser. 5.1 What Time Is It? Recall from Chapter 3, that a JSP page is just a regular HTML page with a few special elements. JSP pages should have the file extension .jsp , which tells the server that the page needs to be processed by the JSP container. Without this clue, the server is unable to distinguish a JSP page from any other type of file and sends it unprocessed to the browser. When working with JSP pages, you really just need a regular text editor such as Notepad on Windows or Emacs on Unix. Appendix E, however, lists a number of tools that may make it easier for you, such as syntax- aware editors that color-code JSP and HTML elements. Some Interactive Development Environments (IDEs) include a small web container that allows you to easily execute and debug the page during development. There are also several web page authoring tools - the type of tools often used when developing regular HTML pages - that support JSP. I don’t recommend that you use them initially; it’s easier to learn how JSP works if you see the raw page elements before you use tools that hide them. The first example JSP page, named date.jsp , is shown in Example 5.1. Example 5.1. JSP Page Showing the Current Date and Time (date.jsp) <%@ page language="java" contentType="text/html" %>
- Date:
- Month:
- Year:
- Hours:
- Minutes:
The date.jsp page displays the current date and time. We’ll look at all the different pieces soon, but first let’s run the example to see how it works. Assuming you have installed all book examples as described in Chapter 4, first start the Tomcat server and load the http://localhost:8080/ora/ URL in a browser. You can then run Example 5.1 by clicking the “Current Date/Time example” link from the book examples main page, shown in Figure 5.1. You should see a result like the one shown in Figure 5.2. page 42
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services
Flash hosting - JavaSercer Pages 4.5 Example Web Application Overview The
November 29, 2006 on 1:15 pm | In Java | No Comments JavaSercer Pages 4.5 Example Web Application Overview The examples for this java blog are packaged as a standard Java web application, as described in Chapter 2. This file structure is supported by all Servlet 2.2-compliant servers, so you can use the example application as a guide when you create your own web applications. How a web application is installed is not defined by the specification, however, so it varies between servers. With Tomcat, you simply copy the file structure to the special webapps directory and restart the server. To modify the configuration information for an application, you need to edit the application’s WEB-INF/web.xml file using a text editor. Other servers may offer special deployment tools that copy the files to where they belong and let you configure the application using a special tool, such as web-based forms. If you look in the ora web application directory, you’ll see that it contains an index.html file and a number of directories corresponding to chapters in this java blog. These directories contain all the example JSP and HTML pages. There’s also a WEB-INF directory with a web.xml file, a lib directory, a classes directory, and a tlds directory: The web.xml file contains configuration information for the example application in the format defined by the Servlet 2.2 specification. It’s too early to look at the contents of this file now; we will return to parts of it when needed. The lib and classes directories are standard directories, also defined by the Servlet 2.2 specification. A common question asked by people new to servlets and JSP (prior to the standard web application format) was, “Where do I store my class files so that the server can find them?” The answer, unfortunately, differed depending on which implementation was used. With the standard web application format, however, it’s easy to answer this question: if the classes are packaged in a JAR file, store the JAR file in the lib directory; otherwise, use the classes directory (with subdirectories mirroring the classes’ package structure). The server will always look for Java class files in these two directories. The lib directory for the example application contains five JAR files. The orataglib_1_0.jar file contains all the Java class files for the custom actions and beans used in this java blog. The jdbc20_stdext_classes.jar file contains classes that are part of the JDBC 2.0 Standard Extension and are used in the database examples. The xalan.jar, xerces.jar, and xsl.jar contain XML parser classes used for an example in Chapter 12. The classes directory contains the class for a servlet used to display the raw source code for the example JSP pages, so you can see what they look like before they are processed by the server. It also contains .properties files containing localized text for the example in Chapter 11. The tlds directory is not defined by the Servlet 2.2 specification, but is the name used by convention for Tag Library Descriptor (TLD) files. Don’t worry about what this means now. As you read through this java blog, it will become clear. If you want to try out some of your own JSP pages, beans, and custom actions while reading this java blog, simply add the files to the example application structure: JSP pages in any directory except under WEB-INF, and Java class files in either the classes or the lib directory, depending on if the classes are packaged in a JAR file or not. If you want to use the book’s custom actions and beans in another application, copy the files in both the lib and tlds directories to the web application structure for the other application. page 41
Note: If you are looking for top 10 and very good webhost to host and run your jsp application check Actions jsp hosting services
JavaSercer Pages Two new directories are created: ora
November 29, 2006 on 7:18 am | In Java | No Comments JavaSercer Pages Two new directories are created: ora and src. The first directory contains all examples described in this java blog, and the second contains the Java source files for the JavaBeans, custom actions, and utility classes used in the examples. The examples’ directory structure complies to the standard Java web application format described in Chapter 2. You can therefore configure any Servlet 2.2-compliant web container to run the examples. If you like to use a container other than Tomcat, be sure to read the documentation for that container. To install the example application for Tomcat, copy the web application directory structure to Tomcat’s default directory for applications, called webapps. Use this command on a Windows platform: C:JSPBook> xcopy /s /i ora %TOMCAT_HOME%webappsora On a Unix platform it looks like this: [hans@gefion /usr/local/jspbook] cp -R ora $TOMCAT_HOME/webapps Recall from Chapter 2 that each web application in a server is associated with a unique URI prefix. When you install an application in Tomcat’s webapps directory, the subdirectory name is automatically assigned as the URI prefix for the application ( /ora in this case). At this point, you must shut down and restart the Tomcat server. After that, you can point your browser to the ora application with the following URL: http://localhost:8080/ora/ You should see a start page, as in Figure 4.3, that contains links for all examples in this java blog. Figure 4.3. JSP book examples start page page 40
Note: If you are looking for best hosting provider to host and run your tomcat application check Astra tomcat hosting services
Google webspace - JavaSercer Pages Figure 4.2. The Tomcat main page
November 29, 2006 on 12:13 am | In Java | No Comments JavaSercer Pages Figure 4.2. The Tomcat main page When you’re done testing Tomcat, stop the server like this: C:Jakartajakarta-tomcatbin> shutdown You should always stop the server this way, as opposed to killing the Command Prompt window the server is running in. Otherwise, the applications don’t get a chance to close down gracefully, and when you start to connect external resources, like a database, various problems may occur. 4.4 Installing the Book Examples All JSP pages, HTML pages, Java source code, and class files for the book examples can be downloaded directly from the O’Reilly web site: http://www.oreilly.com/catalog/jserverpages/ They can also be downloaded from the book web site: http://www.TheJSPBook.com The file that contains all the examples is called jspbook.zip. Save the file on your hard drive, for instance in C:JSPBook on a Windows platform, and unpack it: C:JSPBook> jar xvf jspbook.zip You can use the same command on a Unix platform. page 39
Note: If you are looking for cheapest and affordable webspace to host and run your servlet application check Astra servlet hosting services
Jsp web hosting - JavaSercer Pages 4.2.2 Unix Platforms For Unix, the
November 28, 2006 on 5:24 pm | In Java | No CommentsJavaSercer Pages 4.2.2 Unix Platforms For Unix, the corresponding scripts are named startup.sh, shutdown.sh, and tomcat.sh. Start the server with this command: [hans@gefion /usr/local/jakarta-tomcat/bin] ./startup.sh If you want Tomcat to start each time you boot the system, you can add the following commands to your /etc/rc.d/rc.local (or equivalent) startup script: export JAVA_HOME=/usr/local/jdk1.2.2 export TOMCAT_HOME=/usr/local/jakarta-tomcat $TOMCAT_HOME/bin/startup.sh & Two more subdirectories under the Tomcat home directory are then created the first time you start the server: logs Server log files. If something doesn’t work as expected, look at the files in this directory for clues as to what’s wrong. work A directory for temporary files that are created by the JSP container and other files. This directory is where the servlets generated from JSP pages are stored. 4.3 Testing Tomcat To test the server - assuming you’re running Tomcat on the same machine as the browser and that you’re using the default port for Tomcat (8080) - open a browser and enter the following URL in the Location/Address field: http://localhost:8080/ The Tomcat main page is shown in the browser (see Figure 4.2), and you can now run all servlet and JSP examples bundled with Tomcat to make sure everything works. page 38
Hint: If you are looking for very good and affordable webspace to host and run your java hosting application check Virtualwebstudio java web hosting provider
JavaSercer Pages 4.2.1 Windows Platforms The Windows files (Web hosting linux)
November 28, 2006 on 10:13 am | In Java | No CommentsJavaSercer Pages 4.2.1 Windows Platforms The Windows files are named startup.bat, shutdown.bat, and tomcat.bat. The tomcat.bat file is the main script for controlling the server; it’s called by the two other scripts startup.bat and shutdown.bat. To start the server in a separate window, change directory to the bin directory and run the startup.bat file: C:Jakarta> cd jakarta-tomcatbin C:Jakartajakarta-tomcatbin> startup A new Command Prompt window pops up and you see startup messages like this: 2000-09-01 09:27:10 - ContextManager: Adding context Ctx( /examples ) 2000-09-01 09:27:10 - ContextManager: Adding context Ctx( /admin ) Starting tomcat. Check logs/tomcat.log for error messages 2000-09-01 09:27:10 - ContextManager: Adding context Ctx( ) 2000-09-01 09:27:10 - ContextManager: Adding context Ctx( /test ) 2000-09-01 09:27:13 - PoolTcpConnector: Starting HttpConnectionHandler on 8080 2000-09-01 09:27:13 - PoolTcpConnector: Starting Ajp12ConnectionHandler on 8007 Just leave this window open; this is where the server process is running. If you’re running on a Windows 95 or 98 platform, you may see an error message about “Out of environment space” when you try to start the server. That’s because the default amount of space allocated for environment variables is not enough. To change this default, run this command in the Command Prompt window before you run the startup.bat file again: C:Jakartajakarta-tomcatbin> COMMAND.COM /E:4096 /P This command sets the environment space to 4096 bytes (4 KB). That should be enough for the server. However, If you still get the same message, use a higher value. For some installations, this command may not work. If it doesn’t work, try this instead: 1. Close the Command Prompt window and open a new one. 2. Click on the MS-DOS icon at the top-left of the window. 3. Select the Properties option. 4. Click on the Memory tab. 5. Change the Initial Environment value from Auto to 4096. 6. Click on OK and try to start the server again. At this point, the server may not start due to other problems. If so, the extra Command Prompt window may pop up and then disappear before you have a chance to read the error messages. If this happens, you can let the server run in the Command Prompt window with this command instead: C:Jakartajakarta-tomcatbin> tomcat run On Windows NT, first make sure that the Command Prompt window has a large enough screen buffer so that you can scroll back in case the error messages don’t fit on one screen. Open the Properties window for the Command Prompt window (right mouse button in the upper-left corner), select Layout, and set the screen buffer size height to a large value (for instance 999). Unfortunately, the Command Prompt screen buffer cannot be enlarged for Windows 95/98, so scrolling back is not an option. If you run into problems on these platforms, double-check that you have installed the Java SDK correctly and that you have set the JAVA_HOME and PATH environment variables as described earlier. page 37
Note: If you are looking for good and affordable webspace to host and run your servlet application check Virtualwebstudio servlet hosting services
...I
just wanted to take the time to say "Thank you!" for our new webmail
system. It's great! Thanks for taking such good care of us.
Thanks
for helping me out. Just for the record, Webhostingjava.net has been a great
web host! So far your support and handling of questions has far
exceeded that of a "larger web hosting company".
I
would like to thank you for helping me with my domain...You have
shown me great patience and professionalism. I would not hesitate to
recommend you to my clients.