Users.xml is present in the hard drive, but the prompt: The system cannot find the path specified.
Workaround:
Set the encoding format of a string
1 realpath = Urldecoder.decode (Realpath, "UTF-8");
Source:
1 Packagecn.itcast.utils;2 3 ImportJava.io.File;4 ImportJava.io.FileOutputStream;5 Importjava.io.IOException;6 Importjava.io.UnsupportedEncodingException;7 ImportJava.net.URL;8 ImportJava.net.URLDecoder;9 Ten Importorg.dom4j.Document; One Importorg.dom4j.DocumentException; A ImportOrg.dom4j.io.OutputFormat; - ImportOrg.dom4j.io.SAXReader; - ImportOrg.dom4j.io.XMLWriter; the - Public classXmlutils { - - Private StaticString filename = "Users.xml"; + - Public StaticDocument GetDocument ()throwsdocumentexception, unsupportedencodingexception { + AURL url = xmlutils.class. getClassLoader (). getresource (filename); atString Realpath =Url.getpath (); - -Realpath = Urldecoder.decode (Realpath, "UTF-8"); - -Saxreader reader =NewSaxreader (); - returnReader.read (NewFile (Realpath)); in } - to Public Static voidWrite2xml (document Document)throwsIOException { + -URL url = xmlutils.class. getClassLoader (). getresource (filename); theString Realpath =Url.getpath (); * $Realpath = Urldecoder.decode (Realpath, "UTF-8");Panax Notoginseng -OutputFormat format =outputformat.createprettyprint (); theXMLWriter writer =NewXMLWriter (NewFileOutputStream (Realpath), format); + Writer.write (document); A writer.close (); the } +}
HTTP Status 500–internal Server Error
Type Exception Report
Message org.dom4j.documentexception:c:\program%20files\apache%20software%20foundation\tomcat%208.5\ Webapps\day09_user\web-inf\classes\users.xml (the system cannot find the path specified.) ) Nested exception:c:\program%20files\apache%20software%20foundation\tomcat%208.5\webapps\day09_user\web-inf\ Classes\users.xml (the system cannot find the path specified.) )
Description The server encountered an unexpected condition this prevented it from fulfilling the request.
Exception
java.lang.runtimeexception:org.dom4j.documentexception:c:\program%20files\apache%20software%20foundation\ Tomcat%208.5\webapps\day09_user\web-inf\classes\users.xml (the system cannot find the path specified.) ) Nested exception:c:\program%20files\apache%20software%20foundation\tomcat%208.5\webapps\day09_user\web-inf\ Classes\users.xml (the system cannot find the path specified.) ) Cn.itcast.dao.impl.UserDaoXmlImpl.find (userdaoxmlimpl.java:35) Cn.itcast.service.impl.BusinessServiceImpl.loginUser (businessserviceimpl.java:29) Cn.itcast.web.controller.LoginServlet.doGet (loginservlet.java:23) Cn.itcast.web.controller.LoginServlet.doPost ( loginservlet.java:38) Javax.servlet.http.HttpServlet.service (httpservlet.java:661) Javax.servlet.http.HttpServlet.service (httpservlet.java:742) Org.apache.tomcat.websocket.server.WsFilter.doFilter (wsfilter.java:52)
Root cause
Org.dom4j.documentexception:c:\program%20files\apache%20software%20foundation\tomcat%208.5\webapps\day09_user\ Web-inf\classes\users.xml (the system cannot find the path specified.) ) Nested exception:c:\program%20files\apache%20software%20foundation\tomcat%208.5\webapps\day09_user\web-inf\ Classes\users.xml (the system cannot find the path specified.) ) Org.dom4j.io.SAXReader.read (saxreader.java:266) cn.itcast.utils.XmlUtils.getDocument (xmlutils.java:28) Cn.itcast.dao.impl.UserDaoXmlImpl.find (USERDAOXMLIMPL.JAVA:18) Cn.itcast.service.impl.BusinessServiceImpl.loginUser (businessserviceimpl.java:29) Cn.itcast.web.controller.LoginServlet.doGet (loginservlet.java:23) Cn.itcast.web.controller.LoginServlet.doPost ( loginservlet.java:38) Javax.servlet.http.HttpServlet.service (httpservlet.java:661) Javax.servlet.http.HttpServlet.service (httpservlet.java:742) Org.apache.tomcat.websocket.server.WsFilter.doFilter (wsfilter.java:52)
Note The full stack trace of the root cause are available in the server logs.
Apache tomcat/8.5.24
HTTP Status 500–internal Server Error