明明硬盘中存在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. Problem C Shopping 闭环贪心

    #include <bits/stdc++.h> using namespace std; ; int fa[maxn]; int main(){ int n, m; scanf(&quo ...

  2. sql 180. 连续出现的数字

    编写一个 SQL 查询,查找所有至少连续出现三次的数字. +----+-----+| Id | Num |+----+-----+| 1 | 1 || 2 | 1 || 3 | 1 || 4 | 2 ...

  3. 第六章 组件 55 组件-使用components定义私有组件

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  4. flutter 记录正则匹配

    手机号正则匹配: // 正则匹配 static bool isChinaPhoneLegal(String str) { return new RegExp('^((13[0-9])|(15[^4]) ...

  5. postConstruct执行过程

    使用@PostConstruct注解修饰的方法会在服务器加载Servlet时运行,并且只会执行一次,在构造函数之后,在init方法之前执行: 执行的顺序一次是:构造函数-->autowired依 ...

  6. Java 包装类及其与String转换、进制转换

    一.包装类 1.基本类型和引用类型 Java中的基本类型我们都知道有8种,但是作为基本类型限制功能的发挥,例如整形转String类型等可能需要类方法实现会更加简便.那么八个基本类型对应八个包装类,即引 ...

  7. P4294 [WC2008]游览计划 (斯坦纳树)

    题目链接 差不多是斯坦纳树裸题,不过边权化成了点权,这样在合并两棵子树时需要去掉根结点的权值,防止重复. 题目还要求输出解,只要在转移时记录下路径,然后dfs一遍就好了. #include<bi ...

  8. python在pycharm中导包一直出错的问题

    之前的net在code的子目录中,怎么调试都无法解决.最后用一个简单粗暴的方式,将net直接拿到项目的根目录中.如此即可

  9. 解决power designer 不能自动生成注释 commont 的解决办法只需要3步:

    解决power designer 不能自动生成注释的解决办法只需要3步: 一.快捷键 Ctrl+Shift+X 打开脚本编辑器:(快捷键不能执行的话可以从这个路径执行:Tools --> Exc ...

  10. hive常用日期函数-模板

    已知日期 要求日期 语句 结果 本周任意一天 本周一 select date_sub(next_day('2016-11-29','MO'),7) ; 2016-11-28 本周任意一天 上周一 se ...