美好的一天。我的JSP Web System存在问题,我正在寻求有关传输功能的帮助。
基本上,发送按钮就像一个停用按钮,一旦我点击它,它就会将发送状态(在我的SQLdb中名为dsTransmit)从'pending'更改为'inactive'。我已经复制了我为删除做的代码并进行了一些修改,这是完美的。
但是,当我在“传输”按钮上执行此操作时,它不会转发要更新的数据。但是,它会发送此错误。
类型状态报告,messageNot Found,description所请求的资源不可用。
请注意,我使用的是Glassfish服务器和Netbeans。
这是我的代码
DataAccess.java
public void transmit(int id){
try {
String sql = "UPDATE DailySales SET transmit = 'approved' where dsId = ? ";
PreparedStatement ps = DBUtils.getPreparedStatement(sql);
ps.setInt(1, id);
ps.executeUpdate();
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(DataAccess.class.getName()).log(Level.SEVERE, null, ex);
}
}
Transmit.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package servlet;
import dao.DataAccess;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author Thang
*/
public class Transmit extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String idTemp = request.getParameter("id");
int id = Integer.parseInt(idTemp);
DataAccess da = new DataAccess();
da.transmit(id);
response.sendRedirect("/CRUD_News/AllPost");
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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">
<servlet>
<servlet-name>EditPost</servlet-name>
<servlet-class>servlet.EditPost</servlet-class>
</servlet>
<servlet>
<servlet-name>DeletePost</servlet-name>
<servlet-class>servlet.DeletePost</servlet-class>
</servlet>
<servlet>
<servlet-name>Transmit</servlet-name>
<servlet-class>servlet.Transmit</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>EditPost</servlet-name>
<url-pattern>/edit</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DeletePost</servlet-name>
<url-pattern>/delete</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Transmit</servlet-name>
<url-pattern>/transmit</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
AllPost.jsp(我用于传输功能的按钮)
<center><a href="transmit?id=${p.id}" class="btn btn-default" onclick="return confirm('Are you sure you want to transmit this?');">Transmit</a></center>
有人可以找到我在这里缺少的东西吗?
答案 0 :(得分:0)
It works for me 你能展示你的项目吗?
<a href="transmit?id=${p.id}> ==> <a href=" transmit.do?id=${p.id}
<servlet-mapping>
<servlet-name>Transmit</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>