为什么我的servlet不能调用?请教:help

www203 上海万象文化配送有限公司 信息技术部总监  2003-03-31 10:10:56
报错信息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() {
}
}

请教
...全文
24 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
moumouren 2003-03-31
没有实现goGet方法
回复
li_haizhou 2003-03-31
你的方法定义写错了:
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response,HttpSession session) throws ServletException, IOException {

应该是:
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

session从response中取得
回复
orac203 2003-03-31
把HttpSession session写在下面
HttpSession session = request.getSession() ;
回复
dybine 2003-03-31
怎么调用servlet的?
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2003-03-31 10:10
社区公告
暂无公告