jsp:forward servlet link Tomcat 8 个错误
jsp:forward servlet link Tomcat 8 error
我正在开发基于 JSP 的 Web 应用程序并尝试使用 [=44= 连接到 Servlet ] 8. 显然我的所有代码都是正确的,我已经在 google 中进行了搜索,但是没有任何好的结果与我添加到我的代码中的部分相同。
拜托,我需要帮助,因为我看不出错误在哪里。谢谢!
我的Index.jsp页面:
<%@ page import="java.util.ArrayList"%>
<%@ page import="app.negocio.GestionLibreria"%>
<%@ page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles/miestilo.css">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script type="text/javascript">
</script>
</head>
<body>
<div id="header">
<div id="header-inner">
<div id="logo">
<a href="/" class>
<img src="http://image.casadellibro.com/t1/i/logo-img.png" id="logo-img"
</a>
<a href="/" class>
<img src="http://image.casadellibro.com/t1/i/logo-txt.png" id="logo-txt"
</a>
</div>
<div id="nav-a">
<div id="datos-registro">
</div>
</div>
<div id="nav-b">
<div id="nav-b-inner">
<ul id="nav03" class="delayed-hover">
<li class="dropdown" id="item01"><a href="controlador?" title="Libros">Libros</li>
<li class="dropdown" id="item02"><a href="/editoriales" title="Ebooks">Editoriales</li>
</ul>
</div>
</div>
<div id="header sub">
</div>
</div>
</div>
<div id="body">
<jsp:forward page="/Servlet?">
<jsp:param name="option" value="1"/>
</jsp:forward>
<% List<String> lista = new ArrayList<>();
lista = (List<String>) request.getAttribute("list2");%>
<div id="div-table">
<table id="gridLibros-table">
<tr>
<td><%= lista.size()%></td>
<td>Jackson</td>
<td>94</td>
<td>94</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
<td>94</td>
</tr>
</table>
</div>
</div>
</body>
</html>
Servlet.java
package app.web;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Servlet extends HttpServlet {
public Servlet() {
super();
// TODO Auto-generated constructor stub
}
private void procesar(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String op = request.getParameter("option");
if ("1".equals(op)) {
List<String> lista = new ArrayList<>();
lista.add("number1");
lista.add("number2");
request.setAttribute("todos", list);
RequestDispatcher rd = request.getRequestDispatcher("/index.jsp");
rd.forward(request, response);
}
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
procesar(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
procesar(request, response);
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<display-name>Web_project3</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Servlet</servlet-name>
<servlet-class>app.web.Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet</servlet-name>
<url-pattern>/Servlet</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
错误响应页面:
Estado HTTP 500 - Ha sucedido una excepción al procesar la página JSP /index.jsp en línea 49
type Informe de Excepción
mensaje Ha sucedido una excepción al procesar la página JSP /index.jsp en línea 49
descripción El servidor encontró un error interno que hizo que no pudiera rellenar este requerimiento.
excepción
org.apache.jasper.JasperException: Ha sucedido una excepción al procesar la página JSP /index.jsp en línea 49
46: </div>
47: </div>
48: <div id="body">
49: <jsp:forward page="/ServletLibreria?">
50: <jsp:param name="option" value="1"/>
51: </jsp:forward>
52: <% List<String> lista = new ArrayList<>();
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:567)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:454)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
causa raíz
org.apache.jasper.JasperException: Ha sucedido una excepción al procesar la página JSP /index.jsp en línea 49
46: </div>
47: </div>
48: <div id="body">
49: <jsp:forward page="/Servlet?">
50: <jsp:param name="option" value="1"/>
51: </jsp:forward>
52: <% List<String> lista = new ArrayList<>();
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:567)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:454)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
app.web.ServletLibreria.procesar(ServletLibreria.java:49)
app.web.ServletLibreria.doGet(ServletLibreria.java:60)
javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:741)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:711)
org.apache.jsp.index_jsp._jspService(index_jsp.java:144)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:431)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
您的页面 index.jsp 将调用参数选项等于 1 的 servlet,并转发到 index.jsp。
我认为您不应该在 index.jsp 中使用 jsp:forward,而应该使用简单的 link。
试试这个代码:
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles/miestilo.css">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script type="text/javascript">
</script>
</head>
<body>
<div id="header">
<div id="header-inner">
<div id="logo">
<a href="/" class>
<img src="http://image.casadellibro.com/t1/i/logo-img.png" id="logo-img"
</a>
<a href="/" class>
<img src="http://image.casadellibro.com/t1/i/logo-txt.png" id="logo-txt"
</a>
</div>
<div id="nav-a">
<div id="datos-registro">
</div>
</div>
<div id="nav-b">
<div id="nav-b-inner">
<ul id="nav03" class="delayed-hover">
<li class="dropdown" id="item01"><a href="controlador?" title="Libros">Libros</li>
<li class="dropdown" id="item02"><a href="/editoriales" title="Ebooks">Editoriales</li>
</ul>
</div>
</div>
<div id="header sub">
</div>
</div>
</div>
<div id="body">
<a href="Servlet?option=1">link to servlet with Option 1</a>
<%--<jsp:forward page="/Servlet?">
<jsp:param name="option" value="1"/>
</jsp:forward>--%>
<% List<String> lista = (List<String>) request.getAttribute("lista");
if (lista == null) {
lista = new ArrayList<String>();
}
%>
<div id="div-table">
<table id="gridLibros-table">
<tr>
<td><%= lista.size()%>
</td>
<td>Jackson</td>
<td>94</td>
<td>94</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
<td>94</td>
</tr>
</table>
</div>
</div>
</body>
</html>
package app.web;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Servlet extends HttpServlet {
public Servlet() {
super();
// TODO Auto-generated constructor stub
}
private void procesar(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
String op = request.getParameter("option");
if ("1".equals(op)) {
List<String> lista = new ArrayList<String>();
lista.add("number1");
lista.add("number2");
request.setAttribute("lista", lista);
RequestDispatcher rd = request.getRequestDispatcher("/index.jsp");
rd.forward(request, response);
}
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
procesar(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
procesar(request, response);
}
}
我终于解决了这个问题并真诚地 没有明确的迹象表明它的主要原因是什么。
我创建了一个新项目,并逐步小心地部署相同的代码。我正在使用 Netbeans 8.02 和 Tomcat 8.01.
非常感谢大家!!!
我正在开发基于 JSP 的 Web 应用程序并尝试使用 [=44= 连接到 Servlet ] 8. 显然我的所有代码都是正确的,我已经在 google 中进行了搜索,但是没有任何好的结果与我添加到我的代码中的部分相同。
拜托,我需要帮助,因为我看不出错误在哪里。谢谢!
我的Index.jsp页面:
<%@ page import="java.util.ArrayList"%>
<%@ page import="app.negocio.GestionLibreria"%>
<%@ page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles/miestilo.css">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script type="text/javascript">
</script>
</head>
<body>
<div id="header">
<div id="header-inner">
<div id="logo">
<a href="/" class>
<img src="http://image.casadellibro.com/t1/i/logo-img.png" id="logo-img"
</a>
<a href="/" class>
<img src="http://image.casadellibro.com/t1/i/logo-txt.png" id="logo-txt"
</a>
</div>
<div id="nav-a">
<div id="datos-registro">
</div>
</div>
<div id="nav-b">
<div id="nav-b-inner">
<ul id="nav03" class="delayed-hover">
<li class="dropdown" id="item01"><a href="controlador?" title="Libros">Libros</li>
<li class="dropdown" id="item02"><a href="/editoriales" title="Ebooks">Editoriales</li>
</ul>
</div>
</div>
<div id="header sub">
</div>
</div>
</div>
<div id="body">
<jsp:forward page="/Servlet?">
<jsp:param name="option" value="1"/>
</jsp:forward>
<% List<String> lista = new ArrayList<>();
lista = (List<String>) request.getAttribute("list2");%>
<div id="div-table">
<table id="gridLibros-table">
<tr>
<td><%= lista.size()%></td>
<td>Jackson</td>
<td>94</td>
<td>94</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
<td>94</td>
</tr>
</table>
</div>
</div>
</body>
</html>
Servlet.java
package app.web;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Servlet extends HttpServlet {
public Servlet() {
super();
// TODO Auto-generated constructor stub
}
private void procesar(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String op = request.getParameter("option");
if ("1".equals(op)) {
List<String> lista = new ArrayList<>();
lista.add("number1");
lista.add("number2");
request.setAttribute("todos", list);
RequestDispatcher rd = request.getRequestDispatcher("/index.jsp");
rd.forward(request, response);
}
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
procesar(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
procesar(request, response);
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<display-name>Web_project3</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Servlet</servlet-name>
<servlet-class>app.web.Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet</servlet-name>
<url-pattern>/Servlet</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
错误响应页面:
Estado HTTP 500 - Ha sucedido una excepción al procesar la página JSP /index.jsp en línea 49
type Informe de Excepción
mensaje Ha sucedido una excepción al procesar la página JSP /index.jsp en línea 49
descripción El servidor encontró un error interno que hizo que no pudiera rellenar este requerimiento.
excepción
org.apache.jasper.JasperException: Ha sucedido una excepción al procesar la página JSP /index.jsp en línea 49
46: </div>
47: </div>
48: <div id="body">
49: <jsp:forward page="/ServletLibreria?">
50: <jsp:param name="option" value="1"/>
51: </jsp:forward>
52: <% List<String> lista = new ArrayList<>();
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:567)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:454)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
causa raíz
org.apache.jasper.JasperException: Ha sucedido una excepción al procesar la página JSP /index.jsp en línea 49
46: </div>
47: </div>
48: <div id="body">
49: <jsp:forward page="/Servlet?">
50: <jsp:param name="option" value="1"/>
51: </jsp:forward>
52: <% List<String> lista = new ArrayList<>();
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:567)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:454)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
app.web.ServletLibreria.procesar(ServletLibreria.java:49)
app.web.ServletLibreria.doGet(ServletLibreria.java:60)
javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:741)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:711)
org.apache.jsp.index_jsp._jspService(index_jsp.java:144)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:431)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
您的页面 index.jsp 将调用参数选项等于 1 的 servlet,并转发到 index.jsp。 我认为您不应该在 index.jsp 中使用 jsp:forward,而应该使用简单的 link。 试试这个代码:
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles/miestilo.css">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script type="text/javascript">
</script>
</head>
<body>
<div id="header">
<div id="header-inner">
<div id="logo">
<a href="/" class>
<img src="http://image.casadellibro.com/t1/i/logo-img.png" id="logo-img"
</a>
<a href="/" class>
<img src="http://image.casadellibro.com/t1/i/logo-txt.png" id="logo-txt"
</a>
</div>
<div id="nav-a">
<div id="datos-registro">
</div>
</div>
<div id="nav-b">
<div id="nav-b-inner">
<ul id="nav03" class="delayed-hover">
<li class="dropdown" id="item01"><a href="controlador?" title="Libros">Libros</li>
<li class="dropdown" id="item02"><a href="/editoriales" title="Ebooks">Editoriales</li>
</ul>
</div>
</div>
<div id="header sub">
</div>
</div>
</div>
<div id="body">
<a href="Servlet?option=1">link to servlet with Option 1</a>
<%--<jsp:forward page="/Servlet?">
<jsp:param name="option" value="1"/>
</jsp:forward>--%>
<% List<String> lista = (List<String>) request.getAttribute("lista");
if (lista == null) {
lista = new ArrayList<String>();
}
%>
<div id="div-table">
<table id="gridLibros-table">
<tr>
<td><%= lista.size()%>
</td>
<td>Jackson</td>
<td>94</td>
<td>94</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
<td>94</td>
</tr>
</table>
</div>
</div>
</body>
</html>
package app.web;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Servlet extends HttpServlet {
public Servlet() {
super();
// TODO Auto-generated constructor stub
}
private void procesar(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
String op = request.getParameter("option");
if ("1".equals(op)) {
List<String> lista = new ArrayList<String>();
lista.add("number1");
lista.add("number2");
request.setAttribute("lista", lista);
RequestDispatcher rd = request.getRequestDispatcher("/index.jsp");
rd.forward(request, response);
}
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
procesar(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
procesar(request, response);
}
}
我终于解决了这个问题并真诚地 没有明确的迹象表明它的主要原因是什么。 我创建了一个新项目,并逐步小心地部署相同的代码。我正在使用 Netbeans 8.02 和 Tomcat 8.01.
非常感谢大家!!!