X-cart web hosting - JavaSercer Pages If you run this example in
JavaSercer Pages If you run this example in a Netscape browser, it responds with “You’re using Netscape,” as expected. The problem is that if you run it with Internet Explorer, you get the same response. Clearly there’s something wrong with the way the User-Agent header value is tested. To find out why it doesn’t work with Internet Explorer, you can add a one-line JSP expression that includes the value of the User-Agent header in the response: <%@ page language="java" contentType="text/html" %>
User-Agent header value: <%= request.getHeader("User-Agent") %> … The result is shown in Figure 7.2. Figure 7.2. Response with debug output Now it’s clear why it doesn’t work: the User-Agent header value set by Internet Explorer also contains the string “Mozilla”. So the test in the JSP page must be reversed, first looking for the string “MSIE” (to identify Internet Explorer) and looking for “Mozilla” only if it’s not found. Adding a couple of JSP expressions to see variable values as part of the response in the browser is the easiest way to debug a JSP page. But sometimes multiple pages are involved in the processing of a single request, as you will see in Chapter 8. In this case, it may be better to write the debug output to a file or the command window where you started the server instead. To write to the standard log file for the server, replace the JSP expression with this scriptlet: <% application.log("User-Agent header value: " + request.getHeader("User-Agent")); %> The application variable is one of the implicit JSP objects described in Chapter 6, containing a reference to the javax.servlet.ServletContext object for the application. It provides a log( ) method that writes messages to the application log file. The name and location of the file are server-dependent. With a default configuration of Tomcat, it’s named logs/servlet.log. Most servers, including Tomcat, also let you write messages to the window where the server was started, represented by the System.out object: <% System.out.println("User-Agent header value: " + request.getHeader("User-Agent")); %> This approach works fine during development, when you run your own web server started in a command window, but you need to remember to remove these lines in your production code. Writing to the log file is useful when you debug an application that is running in a web server you don’t have control over, or if you need to record the debug messages in a file for further analysis later. To make it easier to generate the most common types of debug output, you can use the DebugBean class that I developed for this java blog. Its properties represent information that’s available in a JSP page, as shown in Table 7.1. page 80
Note: If you are looking for top 10 and very good webhost to host and run your jsp application check Actions jsp hosting services