明明硬盘中存在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. centos6网络命令

    ifconfig route netstat ss setup ip {link, addr, route}

  2. Vue双向绑定的实现原理系列(四):补充指令解析器compile

    补充指令解析器compile github源码 补充下HTML节点类型的知识: 元素节点 Node.ELEMENT_NODE(1) 属性节点 Node.ATTRIBUTE_NODE(2) 文本节点 N ...

  3. Ubuntu 安装openmpi

    Ubuntu14.04TLS安装openmpi参考:https://likymice.wordpress.com/2015/03/13/install-open-mpi-in-ubuntu-14-04 ...

  4. tcpip入门的网络教程汇总

    网络编程懒人入门(一):快速理解网络通信协议(上篇) http://www.52im.net/thread-1095-1-1.html TCP/IP详解学习笔记 https://www.cnblogs ...

  5. centos7编译安装php7.3

    处理问题   解决php configure: error: Cannot find ldap libraries in /usr/lib.错误 cp -frp /usr/lib64/libldap* ...

  6. Java的日期与时间 java.time.Duration (转)

    一个Duration对象表示两个Instant间的一段时间,是在Java 8中加入的新功能. 一个Duration实例是不可变的,当创建出对象后就不能改变它的值了.你只能通过Duration的计算方法 ...

  7. C#与数据库有关的控件和属性

    BindingNavigator  数据记录导航 BindingSource 与数据源绑定, 常用属性:DataSource.DataMember 常用方法: DataGridView 以表格形式显示 ...

  8. svn版本更新

    1.查看当前版本:svn --version 2.配置svn yum源 tee /etc/yum.repos.d/wandisco-svn.repo <<-'EOF' [WandiscoS ...

  9. Tishreen-CPC 2018 G. Colors Overflow(分块)

    Problem G. Colors Overflow Input file: standard input Output file: standard output Balloon Color: Da ...

  10. vue 使用axios 出现跨域请求的两种解决方法

    最近在使用vue axios发送请求,结果出现跨域问题,网上查了好多,发现有好几种结局方案. 1:服务器端设置跨域 header(“Access-Control-Allow-Origin:*”); h ...