Errors always occur when the XML document is deployed on the Tomcat server.

Source: Internet
Author: User

Config. xnl at first, the document path is in src/Dao/config. xml

In the basedao class under the DaO directory, parsing the config. xml file path = "/Dao/config. xml" seems to be normal. If you can run tomcat, an error is always reported. The system cannot find the specified file path.

I put it under the root directory of SRC/Web-Info and other files, and the system still shows that the specified file path cannot be found. Baidu times, after all the suggestions are invalid, it takes two hours to debug and summarize the two methods.

First, you can directly request the server resources through the URL, so you can put the config. xml file under the web root directory, and then pass the URL path to the parser, as shown in the following figure:

 
PrivateString Config = "http: // localhost: 8081/ch06/config. xml ";

The protocol and port number can be obtained through this method.

 
String Path =Request. getcontextpath (); string basepath= Request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/";

But dependent on the request, it looks awkward.

Second: Later I remembered why the path of the configuration file loaded in hibernate was so dry. I found the configuration. Class file in the hibernate3 package and opened it with The Decompilation software,

I found that I/O streams were used to load path resources. After some deliberation, I finally got it done. The path is still the path above. The code in the basedao class is as follows:

 
PrivateInputstream Config =This. Getclass (). getresourceasstream ("/Dao/config. xml"); Parser. parse (config, GH );

Run Tomcat again to get the result.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.