<script>
function register(){
axios({
method:'GET',
url:'http://localhost:8080/java_web_final2_war_exploded/demo11'
}).then(
response => console.log(response),
error => console.log(error)
)
}
</script>
@WebServlet("/demo11")
public class Register extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// 设置响应内容类型
resp.setContentType("text/plain;charset=UTF-8");
// 响应客户端,通知登录成功
resp.getWriter().write("注册成功!");
}
}
显示报错:GET http://localhost:8080/java_web_final2_war_exploded/demo11 500 (Internal Server Error)
Main_interface.html:459
AxiosError {message: 'Request failed with status code 500', name: 'AxiosError', code: 'ERR_BAD_RESPONSE', config: {…}, request: XMLHttpRequest, …}
code
:
"ERR_BAD_RESPONSE"
config
:
{transitional: {…}, adapter: Array(3), transformRequest: Array(1), transformResponse: Array(1), timeout: 0, …}
message
:
"Request failed with status code 500"
name
:
"AxiosError"
request
:
XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}
response
:
{data: '<title>HTTP状态…/><h3>Apache Tomcat/11.0.0-M21</h3></body></html>', status: 500, statusText: '', headers: AxiosHeaders, config: {…}, …}<br>stack<br>:<br>"AxiosError: Request failed with status code 500\n at settle (<a href="https://cdn.bootcdn.net/ajax/libs/axios/1.7.2/axios.js:2473:14)\n">https://cdn.bootcdn.net/ajax/libs/axios/1.7.2/axios.js:2473:14)\n</a><span style="display:inline-block;text-indent:2em;"> at XMLHttpRequest.onloadend (</span><a href="https://cdn.bootcdn.net/ajax/libs/axios/1.7.2/axios.js:2894:9)\n">https://cdn.bootcdn.net/ajax/libs/axios/1.7.2/axios.js:2894:9)\n</a><span style="display:inline-block;text-indent:2em;"> at Axios._callee$ (</span><a href="https://cdn.bootcdn.net/ajax/libs/axios/1.7.2/axios.js:3710:51)\n">https://cdn.bootcdn.net/ajax/libs/axios/1.7.2/axios.js:3710:51)\n</a><span style="display:inline-block;text-indent:2em;"> at tryCatch (</span><a href="https://cdn.bootcdn.net/ajax/libs/axios/1.7.2/axios.js:232:18)\n">https://cdn.bootcdn.net/ajax/libs/axios/1.7.2/axios.js:232:18)\n</a><span style="display:inline-block;text-indent:2em;"> at Generator.</span><anonymous> (<a href="https://cdn.bootcdn.net/ajax/libs/axios/1.7.2/axios.js:320:19)\n">https://cdn.bootcdn.net/ajax/libs/axios/1.7.2/axios.js:320:19)\n</a><span style="display:inline-block;text-indent:2em;"> at Generator.throw (</span><a href="https://cdn.bootcdn.net/ajax/libs/axios/1.7.2/axios.js:261:23)\n">https://cdn.bootcdn.net/ajax/libs/axios/1.7.2/axios.js:261:23)\n</a><span style="display:inline-block;text-indent:2em;"> at asyncGeneratorStep (</span><a href="https://cdn.bootcdn.net/ajax/libs/axios/1.7.2/axios.js:521:26)\n">https://cdn.bootcdn.net/ajax/libs/axios/1.7.2/axios.js:521:26)\n</a><span style="display:inline-block;text-indent:2em;"> at _throw (</span><a href="https://cdn.bootcdn.net/ajax/libs/axios/1.7.2/axios.js:543:11)"">https://cdn.bootcdn.net/ajax/libs/axios/1.7.2/axios.js:543:11)"</a><br>[[Prototype]]<br>:<br>Error
</p>
</title>