为什么我的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() {
}
}

请教
...全文
138 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
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的?

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧