为什么我的servlet不能调用?请教:help
报错信息type Status report
message HTTP method GET is not supported by this URL
description The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).
代码:
package com.wfsw.bsdt;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class swdj_bg_in extends HttpServlet {
static final private String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response,HttpSession session) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
String yhid = (String)session.getAttribute("yhid") ;
String nsrsbh = (String)session.getAttribute("nsrsbh") ;
String bgxm_dm = request.getParameter("bgxm_dm");
if (bgxm_dm == null) {
bgxm_dm = "";
}
String bghz = request.getParameter("bghz");
if (bghz == null) {
bghz = "";
}
String bgqz = request.getParameter("bgqz");
if (bgqz == null) {
bgqz = "";
}
com.wfsw.dbcon dbcon =new com.wfsw.dbcon() ;
Connection con = dbcon.getConn() ;
Statement stmt = null;
try {
stmt = con.createStatement() ;
}catch (Exception ex) {
}
String sql = "insert into dj_bg(id,yhid,nsrsbh,bgxm_dm,bgqz,bghz) values(dj_bg_id.nextval,"+yhid
+",'"+nsrsbh+"','"+bgxm_dm+"','"+bgqz+"','"+bghz+"')" ;
try {
stmt.executeUpdate(sql) ;
stmt.close();
con.close();
}catch (Exception ex) {
}
out.println("<html>");
out.println("<head><title>swdj_bg_in</title></head>");
out.println("<body>");
out.println("<p>The servlet has received a GET. This is the reply.</p>");
out.println("</body></html>");
response.sendRedirect("bsdt/swdj_bgdj.jsp");
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>swdj_bg_in</title></head>");
out.println("<body>");
out.println("<p>The servlet has received a POST. This is the reply.</p>");
out.println("</body></html>");
}
//Clean up resources
public void destroy() {
}
}
如果把核心代码都去掉就可以调用了:
package com.wfsw.bsdt;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class swdj_bg_in extends HttpServlet {
static final private String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>swdj_bg_in</title></head>");
out.println("<body>");
out.println("<p>The servlet has received a GET. This is the reply.</p>");
out.println("</body></html>");
response.sendRedirect("bsdt/swdj_bgdj.jsp");
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>swdj_bg_in</title></head>");
out.println("<body>");
out.println("<p>The servlet has received a POST. This is the reply.</p>");
out.println("</body></html>");
}
//Clean up resources
public void destroy() {
}
}
请教