Servlet hosting - JavaSercer Pages This is simply a case where
JavaSercer Pages This is simply a case where the opening tag for a JSP expression (<%=) has been mistakenly written as the opening tag for a JSP scriptlet (<%). It looks like an innocent error, but the error message does not give you much help to find it: org.apache.jasper.JasperException: Unable to compile class for JSP D:tmpTomcatjakarta-tomcatworklocalhost_8080%2Fora _0002fch_00037_0002ferror_00036_0002ejsperror6_jsp_0.java:67: Invalid type expression. request.getRequestURI( ) ^ D:tmpTomcatjakarta-tomcatworklocalhost_8080%2Fora _0002fch_00037_0002ferror_00036_0002ejsperror6_jsp_0.java:70: Invalid declaration. out.write("rn Request Protocol: "); ^ 2 errors Again, the scripting code and the generated code clash, resulting in a message that's hard to understand; but at least you can recognize the code from the JSP page and try to see what's really wrong. The misleading and confusing error messages reported for scripting syntax errors are, in my opinion, a big problem, and one that's hard to solve completely, even with better JSP container implementations and tools. It can be minimized, for instance by providing information about where in the JSP page the error is introduced, but it's always hard for a container to pinpoint the real problem when scripting code is mixed with other generated code. My only advice at this point is (again) to avoid scripting code as much as possible. 7.2 Debugging a JSP-Based Application After you have fixed all syntax errors, pat yourself on the back and enjoy the moment. If the application is more than a trivial example, however, this moment will probably be short-lived: you will likely find that one or more things still don't work as you expected. Logic errors, such as not taking care of all possible input combinations, can easily slip into an application during development. Finding and correcting this type of problem is called debugging. For applications developed in compiled languages such as Java, C, or C++, a tool called a debugger is often used in this phase. A debugger steps through the program line by line or runs until it reaches a break point that you have defined, and lets you inspect the values of all variables in the program. With careful analysis of the program flow in runtime, you can discover why it works the way it does, and not the way you want it to. There are debuggers for JSP as well, such as IBM's Visual Age for Java. This product lets you debug a JSP page exactly the same way as you would a program written in a more traditional programming language. But a real debugger is often overkill for JSP pages. If your pages are so complex that you feel you need a debugger, you may want to move code from the pages into JavaBeans or custom actions instead. These components can then be debugged with a standard Java debugger, which can be found in most Java Interactive Development Environments (IDEs). To debug JSP pages, another time-tested debugging approach is usually sufficient: simply add code to print variable values to the screen. Example 7.7 shows how you can use this approach to find an error in a modified version of the browser.jsp page from Chapter 6. Example 7.7. Testing Header Values in the Wrong Order (browser.jsp) <%@ page language="java" contentType="text/html" %>
<% if (request.getHeader("User-Agent").indexOf("Mozilla") != -1) { %> You’re using Netscape. <% } else if (request.getHeader("User-Agent").indexOf("MSIE") != 1) { %> You’re using Internet Explorer. <% } else { %> You’re using a browser I don’t know about. <% } %> page 79Quick Hint: If you are looking for best quality webspace to host and run your tomcat application check Vision tomcat hosting services