• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help: HTTP method GET error

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jay,
Add a method
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doGet(request,response);
}
Sometimes POST might be supported.
Hmenon
 
Ashwin Desai
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic