分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

HTTP Status 500 – Internal Server Error

发布时间:2023-09-06 01:33责任编辑:蔡小小关键词:暂无标签

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

解决办法:

设置String的编码格式

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

源代码:

 1 package cn.itcast.utils; 2 ?3 import java.io.File; 4 import java.io.FileOutputStream; 5 import java.io.IOException; 6 import java.io.UnsupportedEncodingException; 7 import java.net.URL; 8 import java.net.URLDecoder; 9 10 import org.dom4j.Document;11 import org.dom4j.DocumentException;12 import org.dom4j.io.OutputFormat;13 import org.dom4j.io.SAXReader;14 import org.dom4j.io.XMLWriter;15 16 public class XmlUtils {17 18 ????private static String filename = "users.xml";19 20 ????public static Document getDocument() throws DocumentException, UnsupportedEncodingException {21 22 ????????URL url = XmlUtils.class.getClassLoader().getResource(filename);23 ????????String realpath = url.getPath();24 25 ????????realpath = URLDecoder.decode(realpath, "UTF-8");26 27 ????????SAXReader reader = new SAXReader();28 ????????return reader.read(new File(realpath));29 ????}30 31 ????public static void write2Xml(Document document) throws IOException {32 33 ????????URL url = XmlUtils.class.getClassLoader().getResource(filename);34 ????????String realpath = url.getPath();35 36 ????????realpath = URLDecoder.decode(realpath, "UTF-8");37 38 ????????OutputFormat format = OutputFormat.createPrettyPrint();39 ????????XMLWriter writer = new XMLWriter(new FileOutputStream(realpath), format);40 ????????writer.write(document);41 ????????writer.close();42 ????}43 }

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

原文地址:https://www.cnblogs.com/denggelin/p/8151635.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved