• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

HTTP method GET is not supported by this URL

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
/*
* 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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
}
}
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sam Dustin
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya ok...
 
There are 10 kinds of people in this world. Those that understand binary get this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic