In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what are the JSP debugging skills". In the daily operation, I believe many people have doubts about JSP debugging skills. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "what are the JSP debugging skills?" Next, please follow the editor to study!
Use System.out.println ()
System.out.println () can easily mark whether a piece of code is executed. Of course, we can also print out a variety of values. In addition:
1. Since the System object has become the core object of Java, it can be used anywhere without introducing additional classes. The scope of use includes Servlets,JSP,RMI,EJB's,Beans, classes and stand-alone applications.
two。 Compared with stopping running at a breakpoint, outputting with System.out does not have a significant impact on the running process of the application, which is very useful in applications where the timing mechanism is very important.
Next, the syntax for using System.out.println () is given:
System.out.println ("Debugging message")
This is a simple example of using System.out.print ():
"c" uri= "http://java.sun.com/jsp/jstl/core"" > System.out.println "counter" begin= "1" end= "10" step= "1" > "${counter-5}" / > "counter=" + pageContext.findAttribute ("counter");% >
Now, if you run the above example, it will produce the following results:
-4-3-2-1012345
If you are using a Tomcat server, you can find the following in the stdout.log file in the logs directory:
Counter=1counter=2counter=3counter=4counter=5counter=6counter=7counter=8counter=9counter=10
Using this method, variables and other information can be output to the system log to analyze and find out the deep-seated cause of the problem.
Use JDB Logger
The J2SE logging framework provides logging services for any class running in JVM. So we can use this framework to record any information.
Let's rewrite the above code, using logger API in JDK:
"c" uri= "http://java.sun.com/jsp/jstl/core"% >" java.util.logging.Logger "% > Logger.info" counter "begin=" 1 "end=" 10 "step=" 1 "> set var=" myCount "value=" ${counter-5} "/ >" counter= "+ pageContext.findAttribute (" counter ") +" myCount= "+ pageContext.findAttribute (" myCount ") Logger.info (message);% >
Its running result is similar to the previous one, but it can get additional information output to the stdout.log file. Here we use the info method in logger. Let's give a snapshot of the stdout.log file:
24-Sep-2013 23:31:31 org.apache.jsp.main_jsp _ jspServiceINFO: counter=1 myCount=-424-Sep-2013 23:31:31 org.apache.jsp.main_jsp _ jspServiceINFO: counter=2 myCount=-324-Sep-2013 23:31:31 org.apache.jsp.main_jsp _ jspServiceINFO: counter=3 myCount=-224-Sep-2013 23:31:31 org.apache.jsp.main_jsp _ jspServiceINFO: counter=4 myCount=-124-Sep-2013 23:31:31 org.apache.jsp.main_jsp _ JspServiceINFO: counter=5 myCount=024-Sep-2013 23:31:31 org.apache.jsp.main_jsp _ jspServiceINFO: counter=6 myCount=124-Sep-2013 23:31:31 org.apache.jsp.main_jsp _ jspServiceINFO: counter=7 myCount=224-Sep-2013 23:31:31 org.apache.jsp.main_jsp _ jspServiceINFO: counter=8 myCount=324-Sep-2013 23:31:31 org.apache.jsp.main_jsp _ jspServiceINFO: counter=9 myCount=424-Sep-2013 23:31:31 org.apache.jsp.main_jsp _ jspServiceINFO: counter=10 myCount=5
Messages can be sent using various priorities, by using the sever (), warning (), info (), config (), fine (), finer (), finest () methods. The finest () method is used to record the best information, while the sever () method is used to record the most serious information.
Use the Log4J framework to log messages in different files, which are classified based on severity and importance.
Debugging tool
NetBeans is a tree structure, is an open source Java integrated development environment, supports the development of independent Java applications and network applications, but also supports JSP debugging.
NetBeans supports the following basic debugging functions:
1. Breakpoint
two。 Single-step tracking
3. Observation point
For more information, please see the NetBeans user manual.
Use JDB Debugger
You can use the jdb command in JSP and servlets to debug, just like debugging a normal application.
Typically, we debug the sun.servlet.http.HttpServer object directly to see how HttpServer executes JSP/Servlets in response to a HTTP request. This is very similar to debugging applets. The difference is that the applets program is actually debugging sun.applet.AppletViewer.
Most debuggers automatically ignore details when debugging applets because it knows how to debug applets. If you want to transfer debug objects to JSP, you need to do the following two things:
1. Set the debugger's classpath so that it can find sun.servlet.http.Http-Server and related classes.
two。 Set up the debugger's classpath so that it can find your JSP file and related classes. After setting up classpath, start debugging sun.servlet.http.Http-Server. You can set a breakpoint anywhere in the JSP file, as long as you like, and then use your browser to send a request to the server, and you should see the program stop at the breakpoint.
Working with comments
The comments in the program are helpful to the debugging of the program in many ways. Comments can be used in many aspects of a debugger.
JSP uses Java annotations. If a BUG disappears, take a closer look at the code you just commented out, and you can usually find out why.
Head module of client and server
Sometimes it is useful to look at raw HTTP requests and responses when JSP is not running as intended. If you're familiar with the structure of HTTP, you can look directly at request and response and see what's going on with these header modules.
Important debugging skills
Here are two more tips for debugging JSP:
1. Use a browser to display the original page content to distinguish whether it is a formatting problem. This option is usually under the View menu.
two。 Make sure that the browser does not capture the previous request output when forcing a page reload. If you are using a Netscape Navigator browser, use Shift-Reload;. If you are using an IE browser, use Shift-Refresh.
At this point, the study of "what are the JSP debugging skills" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.