点击注册后跳转404

来源:3-7 request对象(上)

柴犬的凝视

2018-08-08 16:11

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>Insert title here</title>

</head>

<body>

<h1>用户注册</h1>

<hr>

<form name="regForm" action="rqeuest.jsp" method="post">

<table>

 <tr>

<td>用户名:</td>

<td><input type="text" name="username"/></td>

 </tr>

 <tr>

<td>爱好:</td>

<td>

<input type="checkbox" name="favorite" value="read">读书

<input type="checkbox" name="favorite" value="music">音乐

<input type="checkbox" name="favorite" value="movie">电影

<input type="checkbox" name="favorite" value="internet">上网

</td>

</tr>

 <tr>

  <td colspan="2"><input type="submit" value="提交"/></td>

 </tr>

</table>

</form>

</body>

</html>

错误页面

Type Status Report

Message /MyJavaWebApp/rqeuest.jsp

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

request.jsp代码

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>Insert title here</title>

</head>

<body>

<h1>request内置对象</h1>

用户名:<%=request.getParameter("username") %><br>

爱好:<%

String[] favorites = request.getParameterValues("favorite");

for(int i=0;i<favorites.length;i++)

{

out.println(favorites[i]+"&nbsp;&nbsp;");

}

%>

</body>

</html>

运行后页面500错误

Type Exception Report

Message An exception occurred processing JSP page /request.jsp at line 13

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /request.jsp at line 13

10: 	用户名:<%=request.getParameter("username") %><br>
11: 	爱好:<%
12: 			String[] favorites = request.getParameterValues("favorite");
13: 			for(int i=0;i<favorites.length;i++)
14: 			{
15: 				out.println(favorites[i]+"&nbsp;&nbsp;");
16: 			}


Stacktrace:
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:580)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


Root Cause

java.lang.NullPointerException
	org.apache.jsp.request_jsp._jspService(request_jsp.java:98)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
	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.


写回答 关注

4回答

  • 我是无知怎么了
    2018-08-16 17:32:04

    出现错误就看报错描述:The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

    原始服务器没有找到目标资源的当前表示形式,或者不愿意公开它的存在。

    reg.jsp的内容都在form表单中,当执行reg.jsp时,就会向服务器请求跳转action所写的jsp页面:request.jsp,执行request.jsp内容

    你的错误是action跳转的页面不存在,或者不愿意被访问

    为低级的拼写错误。


  • 慕粉0915589117
    2018-08-14 12:20:48

    <form name="regForm" action="request.jsp" method="post">

  • 慕神4225693
    2018-08-09 17:31:48

    你的 form表单的action属性 写成了 action=“rqeuest.jsp”

  • LeanOn3629322
    2018-08-08 17:49:15

    <form name="regForm" action="rqeuest.jsp" method="post">


    看是不是文件名打错了  404找不到文件

JAVA遇见HTML——JSP篇

Java Web入门级教程JSP,带你轻松的学习JSP基础知识

248277 学习 · 3071 问题

查看课程

相似问题