java报错404_Java-HTTP错误404请求的资源不可用,Glassfish

这个问题已经在这里有了答案:????????????>????????????Servlet returns “HTTP Status 404 The requested resource (/servlet) is not available”????????????????????????????????????7个

每当我按下“提交操作”按钮将信息发送到控制器时,我总是收到“ HTTP 404状态-找不到:所请求的资源不可用”,我只是想知道是否有什么可以帮助我解决这个令人沮丧的问题.这是我的代码:

LibraryInfo.jsp

pageEncoding="ISO-8859-1"%>

Library Information

Find Book

ISBN Number:

Book.java:

package com.farmani.model;

public class Book {

private int isbn;

private String author;

private String title;

private String status;

public int getIsbn() {

return isbn;

}

public void setIsbn(int isbn) {

this.isbn = isbn;

}

public String getAuthor() {

return author;

}

public void setAuthor(String author) {

this.author = author;

}

public String getTitle() {

return title;

}

public void setTitle(String title) {

this.title = title;

}

public String getStatus() {

return status;

}

public void setStatus(String status) {

this.status = status;

}

}

ConnectionClass.java

package com.farmani.dao;

import java.sql.Connection;

import java.sql.SQLException;

import javax.naming.InitialContext;

import javax.naming.NamingException;

import javax.sql.DataSource;

public class ConnectionClass {

private DataSource dataSource;

public ConnectionClass(){

try{

InitialContext context = new InitialContext();

dataSource = (DataSource)context.lookup("jdbc/employee");

}catch(NamingException ex){

ex.printStackTrace();

}

}

public Connection getConnection(){

Connection conn = null;

try{

conn=dataSource.getConnection();

}catch(SQLException ex){

ex.printStackTrace();

}

return conn;

}

}

LibraryDAO.java

package com.farmani.dao;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import com.farmani.model.Book;

public class LibraryDAO {

private Connection connection;

public LibraryDAO(){

ConnectionClass conn = new ConnectionClass();

connection = conn.getConnection();

}

public Book getBookByISBN(int isbn){

Book bk = new Book();

try{

PreparedStatement preparedStatement = connection.prepareStatement("select * from book where ISBN=?");

preparedStatement.setInt(1,isbn);

ResultSet rs = preparedStatement.executeQuery();

if(rs.next()){

bk.setIsbn(rs.getInt("ISBN"));

bk.setAuthor(rs.getString("author"));

bk.setTitle(rs.getString("title"));

bk.setStatus(rs.getString("status"));

}

}catch(SQLException e){

e.printStackTrace();

}

return bk;

}

}

bookServlet.java:

package com.farmani.controllers;

import java.io.IOException;

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;

import com.farmani.dao.LibraryDAO;

import com.farmani.model.Book;

@WebServlet("/bookServlet")

public class bookServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

private static String BOOK_DETAILS="/LibraryDetails";

private LibraryDAO dao;

public bookServlet() {

super();

dao = new LibraryDAO();

}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

int isbn = Integer.parseInt(request.getParameter("isbn"));

Book bk = dao.getBookByISBN(isbn);

request.setAttribute("Book",bk);

RequestDispatcher view = request.getRequestDispatcher(BOOK_DETAILS);

view.forward(request,response);

}

}

Web.xml:

LibraryWeb

LibraryInfo.jsp

LibraryDetails.jsp

pageEncoding="ISO-8859-1"%>

Book Details

Book Details

  • ISBN: ${Book.isbn}
  • Author: ${Book.author}
  • Title: ${Book.title }
  • Status: ${Book.status}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值