1. 程式人生 > >HTTP method POST is not supported by this URL方法之一

HTTP method POST is not supported by this URL方法之一

最近在做老師佈置的javaweb作業,剛好做到了資料庫的增刪改查,犯錯總是難免的,在我寫完updateUserServlet程式碼後,執行程式碼後出現瞭如圖錯誤

在網上查了很多部落格無果後,開始自己解決問題。

一、



我的想法是在修改完成點選修改按鈕後直接返回到/select查詢頁面以確定自己的程式碼是否被修改了。但是在我點選修改按鈕後。並沒有如我所願跳轉到查詢頁面,而是出現了405錯誤。(這裡我修改了id為2的記錄)


但是我再一次查詢資料庫所有資料時,竟然驚奇的發現我修改的資料修改成功了


可見至少我的sql語句那部分沒有錯

----------UpdateUserServlet程式碼--------------------------

package edu.sctu.javawebnewjdbc.Servlet;
import edu.sctu.javawebnewjdbc.Servlet.dao.UserDao;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import 
java.sql.*; public class UpdateUserServlet extends HttpServlet { @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { int id = Integer.parseInt(req.getParameter("newId")); String name = req.getParameter("newName"); int
age = Integer.parseInt(req.getParameter("newAge")); try { UserDao userDao = new UserDao(); userDao.updateUser(id,name,age); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } req.getRequestDispatcher("/select").forward(req,resp); // req.getRequestDispatcher("return.jsp").forward(req,resp); // resp.sendRedirect("/select"); } }

所以我把重心放在最後那個跳轉語句,從錯誤中我們可以看見post方法不支援這個頁面,然後我又看了跳轉的select頁面

----------selectUserServlet程式碼----------

package edu.sctu.javawebnewjdbc.Servlet;
import edu.sctu.javawebnewjdbc.Servlet.dao.UserDao;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class SelectUserServlet extends HttpServlet {


    @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        List list = new ArrayList<>();
        try {

            list = new UserDao().selectUser();
} catch (ClassNotFoundException e) {
            e.printStackTrace();
} catch (SQLException e) {
            e.printStackTrace();
}

        List listId = new ArrayList<>();
List listName = new ArrayList<>();
List listAge = new ArrayList<>();
listId = (List) list.get(0);
listName = (List) list.get(1);
listAge = (List) list.get(2);
req.setAttribute("listId",listId);
req.setAttribute("listName",listName);
req.setAttribute("listAge", listAge);
req.getRequestDispatcher("/select.jsp").forward(req,resp);
}
}

這個頁面是用的doGet方法。我想可能是這兩個方法有問題。

二、

重點來了,我在網上搜了很多關於forward和direct的區別,發現forward是從伺服器端直接傳到下一個頁面,不經過瀏覽器,資訊共享。direct是把請求返回到客戶端,客戶端再次請求。所以,我大膽的猜想,我使用forward後,該頁面的資訊已經傳到我想要跳轉到的那個頁面,而我的select頁面是用的doGet方法,原頁面是用的doPost方法自然報錯,所以我最終把forward方法改為direct方法,就OK了! PS:小生才疏學淺,第一次寫部落格,不足之處,還望大神些指點一二

相關推薦

HTTP method POST is not supported by this URL方法之一

最近在做老師佈置的javaweb作業,剛好做到了資料庫的增刪改查,犯錯總是難免的,在我寫完updateUserServlet程式碼後,執行程式碼後出現瞭如圖錯誤 在網上查了很多部落格無果後,開始自己解決問題。 一、 我的想法是在修改完成點選修改按鈕後直接返回到/sel

HTTP method POST is not supported by this URL解決

ons ssa cte buffered class over err inpu public 今天寫了個非常簡單的setvlet想測試些東西,寫好了後用postman請求報錯,報錯內容如下 { "timestamp": 1504170113588, "s

HTTP Status 405 - HTTP method POST is not supported by this URL

class rec inf () 有用 serlvet 技術 body res 出現這個問題, 1、在servlet中沒有調用post()方法引起的 2、在serlvet中跳轉沒有用外跳(response.sendRedirect()) 我的是因為第一種,是沒有寫dopo

解決HTTP Status 405 - HTTP method POST is not supported by this URL

最近在寫Update資料的程式碼時,執行程式碼後總是出現了錯誤 HTTP Status 405 - HTTP method POST is not supported by this URL 在我點選修改按鈕後。並沒有跳轉到更新完成後的頁面,而是出現了405錯誤 但是查詢資料庫資料

自己爬過的坑之“HTTP method POST is not supported by this URL

之前練習的時候,寫了個LoginServlet繼承的HttpServlet的小例子,執行的時候一直報HTTP method POST is not supported by this URL,程式碼與報錯如下,控制檯沒有報錯: 提示不支援post方法,但是程式碼

HTTP method POST is not supported by this URL 詳解方案

報這個錯誤提示有兩方面問題:1、在servlet中沒有呼叫post()方法引起的2、在serlvet中跳轉沒有用外跳(response.sendRedirect())我在做專案時,遇到的是1的錯誤,在servlet中沒有呼叫post().我在jsp頁面中提交一個XMLHTTP

關於"HTTP method GET is not supported by this URL"的錯誤

寫好一個Servlet後訪問時丟擲"HTTP method GET is not supported by this URL"的錯誤,先是自己找了一下原因,後又在網路查詢相關的原因後找到解決方案。 問題的原因是用Eclipse生成Servlet時,會在doGet和doPost自動新增預設

Ajax和Servlet互動,報錯HTTP Status 405 – Method Not Allowed HTTP method GET is not supported by this URL

學習慕課網的Ajax + Servlet實現搜尋框智慧提示的時候(https://www.imooc.com/learn/678) 自己打的程式碼Servlet類可以獲取到客戶端通過Ajax非同步傳送過來的資料,但是客戶端怎麼都無法獲取到服務端Servlet回傳的資料。

HTTP Status 405 – Method Not Allowed Type Status Report Message HTTP method POST is not supported b

HTTP Status 405 – Method Not Allowed Type Status Report Message HTTP method POST is not supported by this URL Description The method received

HTTP 405 method GET/POST is not supported

借鑑自:http://www.chawenti.com/articles/2852.html 問題描述: JQuery使用Ajax請求後臺Servlet出現405錯誤,不管是GET還是POST都會發生。 前臺JS/JQuery程式碼: function getServer

【Android】AS報錯:Configuration on demand is not supported by the current version of the Android Gradle

轉載請註明出處,原文連結:https://blog.csdn.net/u013642500/article/details/80218299 【錯誤】 Configuration on demand is not supported by the current version o

appium解決無法通過name屬性識別元素org.openqa.selenium.InvalidSelectorException: Locator Strategy 'name' is not supported for this session

執行程式碼、: public AndroidDriver<AndroidElement> appiumDriver; appiumDriver.findElement(By.name("我的")).click(); 報錯如下:   去到appium安裝目錄下,找到appiu

查詢日誌報錯Spoon is not supported on this hosttype解決(crontab定時任務未執行解決)

背景:kettle換目標庫後,手動執行命令可以入庫,crontab定時任務未執行,查錯記錄: ①先看了定時任務crontab配置    結果沒問題; ②重啟了crontab定時任務  service crond restart  也沒用 ③查看了配置檔案及資源庫路徑

jdk1.8.0_131解除安裝裝上jdk1.8.0_151,更改專案的java版本後eclipse報Project facet Java 1.8 is not supported by target r

jdk1.8.0_131解除安裝裝上jdk1.8.0_151,更改eclipse的installed JREs後eclipse報Project facet Java 1.8 is not supported by target runtime Apache Tomcat v

Restful風格,PUT修改功能請求,表單中存在文件報錯-HTTP Status 405 - Request method 'POST' not supported

for 文件的 文件 roo spring commons 容量 put common 解決方案配置如下 <!-- 配置文件上傳解析器 --> <bean id="multipartResolver" class="org.spri

feign.codec.EncodeException: class ArrayList/HashMap is not a type supported by this encoder

Storm中使用Fegin,因為Storm是通過拓撲自己建立和管理Bolt的,所以在Bolt中使用到了某個FeignClient就無法通過@Service,然後通過@Autowired獲取到FeginClient的例項。 使用下面的程式碼來例項化FeginClient,

inux : inet_protocols: IPv6 support is disabled: Address family not supported by protocol

nim syn lin sendmail 提示 修改 all striped int 在sendmail,命令發送郵件時提示 inux : inet_protocols: IPv6 support is disabled: Address family not suppo

The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 10.0.

data was start pos zed with bre mark star 在PostgreSQL9.6.5 安裝 Postgis2.4.2 出現錯誤 The data directory was initialized by PostgreSQL version

This file's format is not supported or you don't specify a correct format. 解決辦法

版本問題 body ecif 新版 ted you cor spec asp string path = @"c:\請假統計表.xlsx"; Workbook workBook = new Workbook(); workBoo

angularjs post Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.

報錯 lencod pre () ons flight nbsp urlencode 請求參數 現象: 1. angular http 不配置data(請求參數)時不報錯 2. 加上請求參數後,報錯 3. 服務端response.headers().set(HttpHead