只需要一点帮助。
我试图制作一个小型测试项目,但我遇到了这个错误。妥善放置我的所有 JAR 文件和 JSP:
The requested resource (/LibrayManagement/list_of_books_available.jsp) is not available
以下是jsp代码:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Library</title>
</head>
<body>
<form action="Listofbooksaction" method="post">
<h3>List of books available</h3>
<c:forEach var = "list" items = "${requestScope.BooksList}">
<c:out value = "${list[0]}">
</c:out>
</c:forEach>
<input type= "submit" value = "get list">
</form>
</body>
</html>
以下是动作类代码:
import java.sql.* ;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
public class Listofbooksaction extends HttpServlet {
private static final long serialVersionUID = 1L;
String url = "list_of_books_available.jsp";
public Listofbooksaction() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ConnectionsList c = new ConnectionsList() ;
try {
Statement St = c.createconnection();
ResultSet Rs = St.executeQuery("Select * from books_list") ;
System.out.println(Rs);
ArrayList<String> Books_List = new ArrayList<String>();
while(Rs.next())
{
Books_List.add(Rs.getString(1));
}
request.setAttribute("BooksList", Books_List);
response.sendRedirect(url);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
错误堆栈跟踪:
java.lang.IllegalStateException org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:435) Listofbooksaction.doPost(Listofbooksaction.java:62) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)