aspose file tools*
The moose likes Servlets and the fly likes HTTP method GET is not supported by this URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "HTTP method GET is not supported by this URL" Watch "HTTP method GET is not supported by this URL" New topic
Author

HTTP method GET is not supported by this URL

Sam Dustin
Greenhorn

Joined: Feb 02, 2012
Posts: 3
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package control;

import com.a1biz.dao.DAL;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author smoorthy
*/
public class Controller extends HttpServlet {

/**
* Processes requests for both HTTP
* <code>GET</code> and
* <code>POST</code> methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, SQLException {
DAL aDal = new DAL();
Connection aConnection = aDal.getConnection();
Statement aStmt = aConnection.createStatement();
ResultSet rs= null;

if (aConnection != null){

String query = "SELECT * FROM PROJECT";
rs = aStmt.executeQuery(query);
response.setContentType("text/html;charset=UTF-8");
while (rs.next()) {
System.out.println(rs.getInt(1) + " " + rs.getString(2) + ""
+ rs.getString(3) + "" + rs.getString(4) + ""
+ rs.getString(5) + "" + rs.getString(6) + ""
+ rs.getInt(7) + "" + rs.getString(8) + ""
+ rs.getInt(9) + " "+ rs.getInt(10) +"\n"
);
}


}
PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet Controller</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet Controller at " + request.getContextPath() + "</h1>");
out.println("</body>");
out.println("</html>");
}
catch(Exception ex)
{
System.out.println("connection failed");
}

finally {
rs.close();
aStmt.close();
aConnection.close();

}
}
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP
* <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP
* <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
Sam Dustin
Greenhorn

Joined: Feb 02, 2012
Posts: 3
DAL.java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.a1biz.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author smoorthy
*/
public class DAL {

private static String driverClass;
private static String dbUrl;
private static String user;
private static String password;

public DAL(){

try {
driverClass = "com.mysql.jdbc.Driver";
dbUrl = "jdbc:mysql://localhost:3306/a1biz";
user = "root";
password = "mysql";
Object newInstance = Class.forName(driverClass).newInstance();
} catch (Exception ex) {
Logger.getLogger(DAL.class.getName()).log(Level.SEVERE, null, ex);
}
}

public Connection getConnection() {
try
{
Connection conn = DriverManager.getConnection(dbUrl, user, password);
return conn;

}
catch (Exception exc)
{
Logger.getLogger(exc.toString());
return (null);
}
}
}
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61624
    
  67

So what's your question? Just posting a bunch of code isn't going to allow us to help you.

And, please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sam Dustin
Greenhorn

Joined: Feb 02, 2012
Posts: 3
ya ok...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HTTP method GET is not supported by this URL