明明硬盘中存在users.xml,但是提示:系统找不到指定的路径。

解决办法:

设置String的编码格式

 realpath = URLDecoder.decode(realpath, "UTF-8");

源代码:

 package cn.itcast.utils;

 import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLDecoder; import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter; public class XmlUtils { private static String filename = "users.xml"; public static Document getDocument() throws DocumentException, UnsupportedEncodingException { URL url = XmlUtils.class.getClassLoader().getResource(filename);
String realpath = url.getPath(); realpath = URLDecoder.decode(realpath, "UTF-8"); SAXReader reader = new SAXReader();
return reader.read(new File(realpath));
} public static void write2Xml(Document document) throws IOException { URL url = XmlUtils.class.getClassLoader().getResource(filename);
String realpath = url.getPath(); realpath = URLDecoder.decode(realpath, "UTF-8"); OutputFormat format = OutputFormat.createPrettyPrint();
XMLWriter writer = new XMLWriter(new FileOutputStream(realpath), format);
writer.write(document);
writer.close();
}
}

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 (系统找不到指定的路径。) Nested exception: C:\Program%20Files\Apache%20Software%20Foundation\Tomcat%208.5\webapps\day09_user\WEB-INF\classes\users.xml (系统找不到指定的路径。)

Description The server encountered an unexpected condition that 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 (系统找不到指定的路径。) Nested exception: C:\Program%20Files\Apache%20Software%20Foundation\Tomcat%208.5\webapps\day09_user\WEB-INF\classes\users.xml (系统找不到指定的路径。)
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 (系统找不到指定的路径。) Nested exception: C:\Program%20Files\Apache%20Software%20Foundation\Tomcat%208.5\webapps\day09_user\WEB-INF\classes\users.xml (系统找不到指定的路径。)
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 is available in the server logs.


Apache Tomcat/8.5.24

HTTP Status 500 – Internal Server Error的更多相关文章

  1. Tomcat 提示 HTTP Status 500 – Internal Server Error

    错误信息: HTTP Status 500 – Internal Server Error Type Exception Report Message Error instantiating serv ...

  2. HTTP Status 500 ? Internal Server Error

    getWriter()和getOutputStream()不能同时调用 HTTP Status 500 ? Internal Server Error Type Exception Report Me ...

  3. docker镜像下载出现:received unexpected HTTP status: 500 Internal Server Error

    1.镜像下载总是出现报错:received unexpected HTTP status: 500 Internal Server Error 2.尝试多种方法: ①阿里云docke加速器:注册之后, ...

  4. docker下载镜像received unexpected Http status:500 Internal Server Error

    解决办法 1.就是网上说的 关闭selLinue ,但是对我就没用 2.就是不使用镜像加速 ,但是出现连接超时 3.就是加上具体版本号 结果就成功了 [root@localhost ~]# docke ...

  5. zuul网管配置其他服务时 HTTP Status 500 – Internal Server Error

    1.这个错误是由三个原因导致的 (1).我在给类的接口命名的时候前面少加了一个/ (2)给zuul配置路由的时候多加了个服务名,serviceId名称就是spring的name,而不是eureka注入 ...

  6. docker 在push镜像到本地registry出现的500 Internal Server Error

    ]# docker push 192.168.163.131:5000/test The push refers to a repository [192.168.163.131:5000/test] ...

  7. python urllib2导出elasticsearch数据时 返回 "urllib2.HTTPError: HTTP Error 500: Internal Server Error"

    0.业务场景 将ES中某个index的某个字段的所有数据,导出到文件中 1.ES数据导出方法简述 ES数据导出方法,我主要找到了以下几个方面,欢迎大家补充: ES官方API:snapshot and ...

  8. 调用 WebService 浏览器提示 500 (Internal Server Error) 的原因及解决办法

    在 ASP.NET 开发中,WebService部署成站点之后,如果在本地测试WebService可以运行,在远程却显示“测试窗体只能用于来自本地计算机的请求”或 者"The test fo ...

  9. POST 500 Internal Server Error

    今天调试公司web后台时发现一个POST 500 Internal Server Error的错误. 本来VS本地调试没有发现这个问题,然后发布到服务器时才出现了.然后找了好久没找到什么原因,再仔细在 ...

随机推荐

  1. .NET 树型递归

    /// <summary> /// 获取全部水价标准模型 /// </summary> /// <returns></returns> public I ...

  2. python 示例代码5

    示例5:用户输入和格式化输出2(用户输入demo1)

  3. $'\r': command not found

    在Linux下执行程序最省事的方式就是将系统的执行流程封装成一个shell脚本,上传到linux环境中后就可以直接执行了,但是今天在具体实施的时候出现了错误 $'\r': command not fo ...

  4. Linux配置python环境2,安装python

    安装锁需要的依赖包 sudo apt-get -y install gcc-5 g++-5 libc6-dev make build-essential libssl-dev zlib1g-dev l ...

  5. js数据持久化本地数据存储-JSON.parse和JSON.stringify的区别

    JSON.stringify()的作用是将 JavaScript 值转换为 JSON 字符串, 而JSON.parse()可以将JSON字符串转为一个对象. 简单点说,它们的作用是相对的,我用JSON ...

  6. HDU 6043 - KazaQ's Socks | 2017 Multi-University Training Contest 1

    /* HDU 6043 - KazaQ's Socks [ 找规律 ] | 2017 Multi-University Training Contest 1 题意: 一共 n 双袜子编号 1~n,每天 ...

  7. hdu 6076 Security Check

    题 OvO http://acm.hdu.edu.cn/showproblem.php?pid=6076 2017 Multi-University Training Contest - Team 4 ...

  8. node 打包内存溢出 FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

    electron-vue加载了地图 openLayer后,打包就包内存溢出 解决办法: "build": "node --max_old_space_size=4096 ...

  9. 类中定义成员方法。加不加public有什么区别?

    class Trangle{ double sideA, sideB, sideC, area, length; boolean flag; Trangle(double a, double b, d ...

  10. mybatis延迟加载(Collection)

    上篇讲了assocation,同样我们也可以在一对多关系配置的结点中配置延迟加载策略. 结点中也有 select 属性,column 属性. 需求: 完成加载用户对象时,查询该用户所拥有的账户信息. ...