国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

JavaWeb常見錯誤

2019-11-14 22:23:12
字體:
來源:轉載
供稿:網友
javaWeb常見錯誤

1.<a href="customerServlet?method=add">Add</a> 這里method=add不能有空格,否則報錯(空指針異常)

 1 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2     pageEncoding="ISO-8859-1"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 7 <title>Insert title here</title> 8 </head> 9 <body>10     <a href="customerServlet?method=add">Add</a>11     <br>12     <br>13 14     <a href="customerServlet?method=query">Query</a>15     <br>16     <br>17 18     <a href="customerServlet?method=delete">Delete</a>19     <br>20     <br>21 22 </body>23 </html>
View Code
 1 package com.ouyang.dao; 2  3 import java.io.IOException; 4  5 import javax.servlet.ServletException; 6 import javax.servlet.annotation.WebServlet; 7 import javax.servlet.http.HttpServlet; 8 import javax.servlet.http.HttpServletRequest; 9 import javax.servlet.http.HttpServletResponse;10 11 @WebServlet("/customerServlet")12 public class CustomerServlet extends HttpServlet {13     PRivate static final long serialVersionUID = 1L;14 15     protected void doGet(HttpServletRequest request,16             HttpServletResponse response) throws ServletException, IOException {17         doPost(request, response);18     }19 20     protected void doPost(HttpServletRequest request,21             HttpServletResponse response) throws ServletException, IOException {22         String method = request.getParameter("method");23 24         switch (method) {25         case "add":26             add(request, response);27             break;28         case "query":29             query(request, response);30             break;31         case "delete":32             delete(request, response);33             break;34 35         }36 37     }38 39     private void delete(HttpServletRequest request, HttpServletResponse response)40             throws ServletException, IOException {41         System.out.println("delete");42     }43 44     private void query(HttpServletRequest request, HttpServletResponse response)45             throws ServletException, IOException {46         System.out.println("query");47     }48 49     private void add(HttpServletRequest request, HttpServletResponse response)50             throws ServletException, IOException {51         System.out.println("add");52 53     }54 55 }
View Code

2.url-pattern 中在建立Servlet時前面不應該加"/".否則會報錯


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高台县| 固安县| 汾西县| 雷波县| 瑞金市| 武隆县| 新乡县| 华亭县| 遵义县| 梧州市| 金寨县| 平远县| 南昌市| 新津县| 准格尔旗| 威宁| 张北县| 黑河市| 盐城市| 积石山| 江西省| 和硕县| 文成县| 苏尼特右旗| 遂昌县| 景德镇市| 巴楚县| 泊头市| 缙云县| 漠河县| 栖霞市| 邵阳县| 扬中市| 怀仁县| 琼结县| 淄博市| 大余县| 海安县| 西平县| 西平县| 青冈县|