当前位置:网站首页>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.RequestPay
4.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 committd
4.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
边栏推荐
猜你喜欢
STM32 full series development firmware installation guide under Arduino framework
[Open class preview]: Research and application of super-resolution technology in the field of video image quality enhancement
Unity 之 音频类型和编码格式介绍
全平台GPU通用AI视频补帧超分教程
[Intensive reading of the paper] iNeRF
Memblaze released the first enterprise-grade SSD based on long-lasting particles. What is the new value behind it?
Teach you how to deploy Nestjs projects
高效并发:Synchornized的锁优化详解
Implementation of a sequence table
How programmers learn open source projects, this article tells you
随机推荐
角色妆容的实现
请问我的这段sql中sql语法哪里出了错
Qualcomm cDSP simple programming example (to query Qualcomm cDSP usage, signature), RK3588 npu usage query
MySQL---operator
MySQL---aggregate function
第六章
One thing to say, is outsourcing company worth it?
C language parsing json string (json object is converted to string)
Memblaze发布首款基于长存颗粒的企业级SSD,背后有何新价值?
Basics of ResNet: Principles of Residual Blocks
find prime numbers up to n
【AcWing】第 62 场周赛 【2022.07.30】
STM32 full series development firmware installation guide under Arduino framework
leetcode 665. Non-decreasing Array 非递减数列(中等)
基于STM32 环形队列来实现串口接收数据
Get Douyin Video Details API
leetcode 665. Non-decreasing Array
Linux environment redis cluster to build "recommended collection"
NVIDIA已经开始测试AD106和AD107 GPU核心的显卡产品
Chapter VII