I DOM4J to use this XML file , the file on the web-inf directory, I get this way ,
request.getSession (). getServletContext (). getRealPath ("/ WEB-INF/dao.xml");
File file = new File (path);
Document doc = reader.read (file);
hint system can not find the file specified , the file is null,
This should be how to get ? Thank
------ Solution ------------------------------ --------------
request.getSession (). getServletContext (). getRealPath ("/ WEB-INF/dao.xml");
you print it out see if it is right on the line.
------ Solution ---------------------------------------- ----
there is a way to get the current class path method to obtain the path to the parent directory in acquiring it. .
way you found it, I forgot
------ Solution ---------------------------- ----------------
File file = new File ("C: \ Users \ LeiYu \ Code \ Java \ ThOA \ build \ web \ WEB -INF \ dao.xml "); you first try to use absolute paths . .
------ For reference only ---------------------------------- -----
directly print out is C: \ Users \ LeiYu \ Code \ Java \ ThOA \ build \ web \ WEB-INF \ dao.xml, the path is correct
But SAXReader reader = new SAXReader ();
File file = new File (path);
Document doc = reader.read (file);
After this , the file name will is NULL, it will report the following error ,
org.dom4j.DocumentException: C: \ Users \ LeiYu \ Code \ Java \ ThOA \ build \ web \ WEB-INF \ null ( system can not find the file specified. )
Nested exception: C: \ Users \ LeiYu \ Code \ Java \ ThOA \ build \ web \ WEB-INF \ null ( system can not find the file specified .)
------ For reference only --------- ------------------------------
Do not do that , because this class to make bags, then in the specific web reference ..
------ For reference only -------------- -------------------------
still the same error message , is it does not have permission ??
------ For reference only --------------------- ------------------
finally found the problem , the original DTD is not set right, , actually will be prompted to file does not exist ..
没有评论:
发表评论