wood burning stoves 2.0*
The moose likes Servlets and the fly likes Help: HTTP method GET error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Help: HTTP method GET error" Watch "Help: HTTP method GET error" New topic
Author

Help: HTTP method GET error

Jay X Brown
Ranch Hand

Joined: Jan 26, 2001
Posts: 51
i am experimentally trying to retreive stuff from a database but i am getting an error i cannot figure out.
i attach the servlet and the error message below.
any and all help is appreciated.
jb
entire servlet:
====
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;
public class country_info_servlet extends HttpServlet {
private Connection dbaseConn = null;
private static PrintWriter out;
private Cookie[] MyCookies;
private String uid;
private String encrypteduid;
public void init(ServletConfig config) throws ServletException {
super.init(config);
try {
dbaseConn = makeConnection();
}
catch (Exception ex) {
log("Sybase Connect Error: "+ex.getMessage());
}
}
private void createpage(String pathInfo) throws Exception {
ResultSet MerchantQuery;
Statement query;
out.println("<html><body>");
out.println("<tr><td width=\"700\" colspan=2><img src="+
"\"http://....m/images/....gif\" width=\"500\" "+
"height=\"108\" alt=\"\"></td></tr>");
out.println("<P><a href=https....com/cgi-bin/payment/checkout.pl>View Shopping Cart "+
"and Checkout</a>");
out.println("<h1>Country Information</h1>");
query = dbaseConn.createStatement();
MerchantQuery = query.executeQuery(
"select country_code,country_name,worldarea from sjcnt");
while (MerchantQuery.next())
{
String country_code = MerchantQuery.getString("country_code");
String country_name = MerchantQuery.getString("country_name");
String worldarea = MerchantQuery.getString("worldarea");
out.println("<h2><a href=\"../servlet/country_info_servlet/"+">"+"CODE: "+country_code+"NAME: "+country_name+"GLOBAL REGION: "+worldarea+"</a></h2>");
}
MerchantQuery = query.executeQuery(
"select merchantnr,name from Merchant m "+
"where exists (select 'X' from MerchantProducts where "+
"merchantnr = m.merchantnr and mart = 'SER')");
while (MerchantQuery.next()) {
String name = MerchantQuery.getString("name");
int merchantnr = MerchantQuery.getInt("merchantnr");
out.println("<h2><a href=\"../servlet/testdb/S"+merchantnr+
"\">"+name+"</a></h2>");
}
query.close();
}
private Connection makeConnection() throws Exception
{
Properties dbaseProps = new Properties();
dbaseProps.put("server", "...SERVER");
dbaseProps.put("db", "M...db");
dbaseProps.put("user", "sa");
dbaseProps.put("password", "....");
dbaseProps.put("SERVICENAME", "...");
String jdbcDriver = "com.sybase.jdbc.SybDriver";
String jdbcUrl = "jdbc:sybase:Tds:...:2500/...db";
Class.forName(jdbcDriver).newInstance();
return DriverManager.getConnection(jdbcUrl, dbaseProps);
}
}
====
I get the following error:
> Error: 400
> HTTP method GET is not supported by this URL
====

[This message has been edited by Jay Brown (edited February 14, 2001).]
Ashwin Desai
Ranch Hand

Joined: Jul 17, 2000
Posts: 124
Hi Jay,
You need to have a doGet() method implementation in your servlet.
The default implementation of the doGet() in the HttpServlet class returns you an HTTP error which is what you are getting.

the implementation could be as follows:
public void doGet(request, response)
{
// Note that the writer is obtained here and not as a static variable.
PrintWriter out = response.getWriter();
// Execute the query.
while(resultset.next())
{
out.println(rs.get.......); // your data.
}

out.close();
}
Hope this helps.
Jay X Brown
Ranch Hand

Joined: Jan 26, 2001
Posts: 51
i tried and i tried and i'm still getting the same error. for a while it went away and i was getting a read error.
now i've simplified the servlet quite a bit, rewritten it from scratch.

i'm attaching it below.
help is gratefully appreciated.
thanks
jay
-----
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.sql.*;
import java.net.*;
import java.io.*;
public class om extends HttpServlet {
public Connection c=null;
public PrintWriter out;
final static private String driver = "com.somedatabase.jdbc.SomeDriver";
final static private String user = "username";
final static private String pass = "password";
final static private String url = "jdbc:blah:blah.balh.com:2500/Somedb";
// ******************************
// ** INIT **
// ******************************
public void init (ServletConfig config) throws ServletException
{
super.init(config);
//hit the database
try
{
Class.forName (driver);
c = DriverManager.getConnection(url,user,pass);
}
catch (java.sql.SQLException e)
{
System.out.println("Cannot get connection");
System.exit(1);
}
catch (java.lang.ClassNotFoundException e)
{
System.out.println("Driver class not found");
}
}
// ******************************
// ** doGET **
// ******************************
public void doGET(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
try
{
Class.forName (driver);
c = DriverManager.getConnection(url,user,pass);
}
catch (java.sql.SQLException e)
{
System.out.println("Cannot get connection");
System.exit(1);
}
catch (java.lang.ClassNotFoundException e)
{
System.out.println("Driver class not found");
}
out = response.getWriter();
//Reading & writing HTML
out.println("<html><title>Country Table</title>" +
"<body bgcolor=00B2EB>");
out.println("<h1>This here's 'Country Information' hot from the database!</h1>");
try
{
Statement stmt = c.createStatement();
ResultSet results = stmt.executeQuery("select * from sjcnt");
while(results.next())
{
String country_code = results.getString("country_code");
String country_name = results.getString("country_name");
String worldarea = results.getString("worldarea");
out.println("<br><h2>CODE: "+country_code+"</h2>");
out.println("<br><h2>NAME: "+country_name+"</h2>");
out.println("<br><h2>GLOBAL REGION: "+worldarea+"</h2>");
}
stmt.close();
}
catch(java.sql.SQLException e)
{
System.out.println("Cannot create SQL statement");
System.exit(1);
}
out.println("</body></html>");
}
catch (Exception ex)
{
out.println("Read Error: "+ex.getMessage());
}
out.close();
}
}
-----
error statement:
Error: 400
Location: /hellowww/servlet/om
HTTP method GET is not supported by this URL
Hema Menon
Ranch Hand

Joined: Oct 29, 2000
Posts: 569
Jay,
Add a method
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doGet(request,response);
}
Sometimes POST might be supported.
Hmenon


~hm
Ashwin Desai
Ranch Hand

Joined: Jul 17, 2000
Posts: 124
Jay,
The method is doGet() and not doGET(). Also, do you use a http:// URL to access the servlet?
Ashwin.

[This message has been edited by Ashwin Desai (edited February 16, 2001).]
Jay X Brown
Ranch Hand

Joined: Jan 26, 2001
Posts: 51
Thanks Ashwin,
I feel really foolish on that one.
We are using Tomcat to run the servlets. I'm not sure but I don't think it's an HTTP call. The thing is that other messy cut and paste servlets are running without hitch. Right now our Tomcat is messed up so I can't test the solution but it at least compiled without incident.
Thanks once again.
Jay
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help: HTTP method GET error
 
Similar Threads
Servlet becomming slow
Servlet becomming slow
Connection Pooling
Unable to execute insertion!
javax. servlet.Servlet Exception: Initialization failed, Unable to get DB connection