亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

讀取數據生成空值

讀取數據生成空值

萬千封印 2022-09-28 14:23:21
我有一個包含數據的表。我想添加一條新記錄。但是在某些時候,不可能考慮我引入的內容 控制臺 顯示 null。讀取數據生成空值帖子.jsp <h3 align="left">        <label id="name_form_genre">Добавить должность</label>    </h3>    id Должности:    <input type="text" id="post_id" style="width: 270px;" maxlength="15" value=""/>    Название:    <input type="text" id="post_name" style="width: 270px;" maxlength="15" value=""/>    <div align="left"> <button onclick="add_post()" id="button_form_post">Добавить</button></div>示例.js:function add_post() {var post_id = document.getElementById("post_id");var post_name = document.getElementById("post_name");if(post_id.value.toString().trim()=="" || post_name.value.toString().trim()==""){    alert("Поля не должны быть пустые!")}else {    var xhr = new XMLHttpRequest();    var body = 'action=add' + '&id=' + post_id.value + '&name=' + post_name.value;    xhr.open("POST", "post", false);    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");    xhr.send(body);    if (xhr.status != 200)        alert(xhr.status);    window.location = "/post";}}郵遞.java:@WebServlet("/post")public class PostServlet extends HttpServlet{private PostService postService = new PostService();public PostServlet() throws SQLException, ClassNotFoundException { }protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    processRequest(request, response);}protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    request.getRequestDispatcher("post.jsp").forward(request, response);}有人可以幫助確定問題嗎?提前致謝。
查看完整描述

1 回答

?
白衣染霜花

TA貢獻1796條經驗 獲得超10個贊

您正在文件中設置請求參數,但獲取請求參數和 java。你能在你的請求中驗證它嗎?錯誤消息顯示 該和 為 null。idname.jspost_idpost_namepost_idpost_name

使用 和 代替。idname

postEntity.setPost_id(Integer.parseInt(request.getParameter("id")));
postEntity.setPost_name(request.getParameter("name"));


查看完整回答
反對 回復 2022-09-28
  • 1 回答
  • 0 關注
  • 92 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號