当前位置:网站首页>A solution to the server encountered an internal error that prevented it from fulfilling this request [easy to understand]
A solution to the server encountered an internal error that prevented it from fulfilling this request [easy to understand]
2022-07-31 20:48:00 【Full stack programmer webmaster】
大家好,又见面了,我是你们的朋友全栈君.
An abnormally caused oolong,HTTPStatus500A scenario and a solution to the problem
一、前言
This is the problem I'm having when writing a server response to judge user data,这只是 The server encountered an internal error that prevented it from fulfilling this request A case of the problem,具体错误如下图所示:
二、问题描述
I am setting a property grade 时,设置为 int<11> .when testing data,The form submission data exceeds the original set range,caused by the exception.
2-1 问题解决的方法
Catch exceptions,仅仅捕获了 SQLException,cause other exceptions to occur,被抛出.
try{
// ...
} catch(SQLException e) {
e.printStackTrace();
}捕获异常 Exception 即可
try{
// ...
} catch(Exception e) {
e.printStackTrace();
}2-2 Problems arise and are resolved
Enter the correct information in the input information field,will give the correct prompt
The correct response result after processing is shown on the right
三、问题解决
3-1 解决思路一
In fact, the solution to the problem is standardized development,Dynamic monitoring of the content filled in the text field for filling in the information,Defines what can be entered as numbers,大小写英文,Controls such as entering special characters are not allowed.For example, fill in the user when registering a user ID 时可通过 Ajax 动态获取后台数据,验证该 ID 是否已存在,If it exists on the registration page, it will prompt this ID 已被注册
3-2 解决思路二
Here I use this idea to avoid the problem.When the input information is wrong,Gives an error handling method not written by me,(My error handling is ,给出提示:系统繁忙,Do it later!)Enter data outside of the original range.This is handled by catching the thrown exception,Jump to an operation failure page
The error that appears after clicking OK is as follows:
Go back and check the file code,多次修改,Found a solution to this problem:
修改前的代码:
修改后的代码:(The red line is marked)
保存修改,重新运行程序,
Incorrect data entered,The processing method I have set is given:(下图所示)
当出现异常时,Carefully check the correctness of the code,Maybe just a character,Capitalization or misspelling of words,Enough for you to debug all afternoon.养成良好的代码风格,也是必须的.
四、Other exceptions added
4.1 空指针异常(NullPointerException 先看一下)
HTTP Status 500 - Request processing failed; nested exception is
java.lang.NullPointerException
com.dorm.action.CounsellorAction.counsellorAdd(CounsellorAction.java:123)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)
...
首先sun.* 或者org.*,都是源码,These messages are not investigationsBug 的重点
Generally, the exception thrown is a loophole in your own business code, It will trigger a series of information throwing;
Find the exception information firstCause by ... This is why this exception is thrown,
Then look at the first item in the exception information and the business code related to the current project,
See what information a method of a specified class throws a null pointer exception for a certain behavior.
For example, the above is written by myselfCounsellorAction.java 文件中方法counsellorAdd 抛出的异常,
Found in the run123 behavior existsnull 的对象.4.2 Entity class object conversion exception
This converting object cannot be directly cast to the converted object.
HTTP Status 500 - Request processing failed; nested exception is java.lang.ClassCastException:
com.zduod.core.requestentity.RequestUser cannot be cast to com.zduod.core.requestentity.RequestPay4.3 JSON参数转换异常
JSONData transfer parameter exception,Cannot convert non-numeric to numeric
HTTP Status 500 - Request processing failed; nested exception is com.alibaba.fastjson.JSONException
...
root cause
java.lang.NumberFormatException
java.math.BigDecimal.<init>(BigDecimal.java:494)
java.math.BigDecimal.<init>(BigDecimal.java:383)
java.math.BigDecimal.<init>(BigDecimal.java:806)
com.alibaba.fastjson.util.TypeUtils.castToBigDecimal(TypeUtils.java:194)
...4.4 服务器响应already committed异常
response 是服务端对客户端请求的一个响应,其中封装了响应头、状态码、内容等;服务端在把response提交到客户端之前,会向缓冲区内写入响应头和状态码,Then put everythingflush,That is, all cached output.This marks that the response has been submitted.
对于当前页面already commitd 已经提交的response 就不能再使用response 执行写操作.
HTTP Status 500 - java.lang.IllegalStateException:Cannot forward a response that is already committd4.5 Front-end and back-end interaction data types do not match
Background development query user interface,访问接口
http://localhost:8082/dboot/eouser/queryEOUser,请求JSON数据为
{ "treasureData": "{\"userName\":\"78\",\"userId\":\"2147483648\",\"userPassword\":\"930915\"}"}Background response result
{
"timestamp": "2018-07-13T03:05:36.261+0000",
"status": 500,
"error": "Internal Server Error",
"message": "For input string: \"2147483648\"",
"path": "/dboot/eouser/queryEOUser"
}The interface response error message is input输入数据为String类型,Background request body encapsulates entity class definition propertiesuserId为Integer类型.Integer.MAX_VALUE=2147483647,此处2147483648已经不能作为Integer处理.The interface data is changed to-2147483648 ~ 2147483647之间的整型数据,重新请求接口,The background processes the request normally and returns the result.
{
"eoUserList": [
{
"userId": 1,
"userName": "eolinker",
"userNickName": "eolinker",
"userPassword": "c0bc7b2052c950c1541692eab1284937"
}
],
"errorMsg": "查询用户成功!",
"success": true
}4.6 MybatisError parsing entity property
The exception here is a type exception;异常信息如下
HTTP Status 500 – Internal Server Error
Type Exception Report
Message Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException:
nested exception is org.apache.ibatis.reflection.ReflectionException:
There is no getter for property named 'useId' in 'class com.zduod.manage.face.entity.ZddInformation'此处是因为mybatisError parsing attribute,信息为useIdThere is no counterpart in the entity classsetter()、getter()方法.Check and find that the request parameter is userId,The entity class attribute is userId,也存在对应的setter()、getter()方法.
config file heremapper.xmlmisspelleduserId为useIdCauses an error in parsing the data,服务器无法处理请求.
<select id="getListByPage" resultMap="BaseResultMap" parameterType="com.zduod.manage.face.entity.ZddInformation">
select
<include refid="Base_Column_List" />
from zdd_information
<where>
<if test="informationId != null" >
and information_id = #{informationId,jdbcType=VARCHAR}
</if>
<if test="userId != null" >
<!--typo hereuserId为#{useId,jdbcType=DECIMAL}-->
and user_id = #{userId,jdbcType=DECIMAL}
</if>
</where>
order by create_time desc
</select>4.7 Request data type syntax error
此处异常为JSONThe data has a format error,嵌套异常,语法错误.
HTTP Status 500 – Internal Server Error
Type Exception Report
Message Request processing failed; nested exception is com.alibaba.fastjson.JSONException: syntax error, expect {, actual string, pos 0
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is com.alibaba.fastjson.JSONException: syntax error, expect {, actual string, pos 0异常信息是JSONThe data has a syntax error,在 { There is a problem with nesting of braces.I am here is the front end is throughJSONData request backend interface,仔细检查后JSONThe format of the data has the following problems:JSON请求数据中treasureData的valueValue-nested data is not fully useful{}封装.
修改前:
"treasureData": "{"userId":"2018071211901416892","userPayPassword":"100000","cashBalance":"80""
修改后:
"treasureData": "{"userId":"2018071211901416892","userPayPassword":"100000","cashBalance":"80"}"五、其他说明
500状态码,Problems arise in various situations,请根据Exception信息分析,进行debugBreakpoint debugging to check the specific cause.You can post the exception information,Put it into technical Q&Ahttps://ask.csdn.net/to ask a question,Someone will help you analyze the problem.You can post key exception information in the comment area of this article,The exact cause cannot be determined without exception information.
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/127860.html原文链接:https://javaforall.cn
边栏推荐
- Linux环境redis集群搭建「建议收藏」
- 每月一书(202207):《Swift编程权威指南》
- cas and spin locks (is lightweight locks spin locks)
- PCB叠层设计
- linux view redis version command (linux view mysql version number)
- Poker Game in C# -- Introduction and Code Implementation of Blackjack Rules
- 第六章
- Book of the Month (202207): The Definitive Guide to Swift Programming
- Three. Introduction to js
- focus on!Haitai Fangyuan joins the "Personal Information Protection Self-discipline Convention"
猜你喜欢

Shell script quick start to actual combat -02

STM32 full series development firmware installation guide under Arduino framework

Financial profitability and solvency indicators

Implementation of a sequence table

【论文精读】iNeRF

Getting Started with Tkinter

Socket回顾与I/0模型

Redis综述篇:与面试官彻夜长谈Redis缓存、持久化、淘汰机制、哨兵、集群底层原理!...

ResNet的基础:残差块的原理

Three.js入门
随机推荐
BM3 flips the nodes in the linked list in groups of k
NVIDIA has begun testing graphics products with AD106 and AD107 GPU cores
老牌音乐播放器 WinAmp 发布 5.9 RC1 版:迁移到 VS 2019 完全重建,兼容 Win11
pytorch lstm时间序列预测问题踩坑「建议收藏」
leetcode 665. Non-decreasing Array 非递减数列(中等)
多线程之锁
Short-circuit characteristics and protection of SiC MOSFETs
Thymeleaf是什么?该如何使用。
Shell 脚本 快速入门到实战 -02
NVIDIA已经开始测试AD106和AD107 GPU核心的显卡产品
ResNet的基础:残差块的原理
ReentrantLock原理(未完待续)
高通cDSP简单编程例子(实现查询高通cDSP使用率、签名),RK3588 npu使用率查询
深度学习中的batch(batch size,full batch,mini batch, online learning)、iterations与epoch
统计UTF-8字符串中的字符函数
PCB叠层设计
A shortcut to search for specific character content in idea
INeuOS industrial Internet operating system, the equipment operational business and "low code" form development tools
BM3 将链表中的节点每k个一组翻转
sqlite3简单操作