my answer

my answer

import com.mysql.jdbc.Connection; import com.mysql.jdbc.Statement; import java.io.IOException; import java.io.PrintWriter; import java.sql.DriverManager; import java.sql.ResultSet; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;

/** * * @author ignite178 */ public class view extends HttpServlet { private ServletResponse response;

/**
 * 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 {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
        /*
         * TODO output your page here. You may use following sample code.
         */
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet hit</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet hit at " + request.getContextPath() + "</h1>");
        out.println("</body>");
        out.println("</html>");
    } finally {
        out.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 {

// try { // try { // Class.forName("com.mysql.jdbc.Driver").newInstance(); // } catch (InstantiationException ex) { // Logger.getLogger(view.class.getName()).log(Level.SEVERE, null, ex); // } catch (IllegalAccessException ex) { // Logger.getLogger(view.class.getName()).log(Level.SEVERE, null, ex); // } // } catch (ClassNotFoundException ex) { // Logger.getLogger(view.class.getName()).log(Level.SEVERE, null, ex); // } // Connection con = null; // try { // con = DriverManager.getConnection("jdbc:mysql://localhost:3306/location", "root", "root"); // } catch (SQLException ex) { // Logger.getLogger(view.class.getName()).log(Level.SEVERE, null, ex); // } // String id=request.getParameter("id"); // String query = "select * from posting where ignite_id='"+id+"'"; // Statement s = null; // try { // s = con.createStatement(); // } catch (SQLException ex) { // Logger.getLogger(view.class.getName()).log(Level.SEVERE, null, ex); // } // ResultSet rs = null; // try { // rs = s.executeQuery(query); // } catch (SQLException ex) { // Logger.getLogger(view.class.getName()).log(Level.SEVERE, null, ex); // } // request.setAttribute("data", rs); // RequestDispatcher rd = request.getRequestDispatcher("view.jsp"); // rd.forward(request, response); // } } /** * Handles the HTTP * POST 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 {
    PrintWriter out = response.getWriter();
    String Id = request.getParameter("id");

    try {
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/location", "root", "root");
        String id=request.getParameter("id");
    String query = "select * from posting where ignite_id='"+id+"'";
    Statement s = null;
        s = (Statement) con.createStatement();
        ResultSet rs = null;
         rs = s.executeQuery(query);
          request.setAttribute("data", rs);
    RequestDispatcher rd = request.getRequestDispatcher("view.jsp");
    rd.forward(request, response);              

  } catch (Exception e) {
        out.print(e.toString());
    } finally {

        out.close();

    }
}

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

}

View Answers

May 21, 2013 at 5:03 PM

import com.mysql.jdbc.PreparedStatement; import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; import java.sql.DriverManager; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;

/** * * @author ignite178 */ public class hit 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 {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
        /*
         * TODO output your page here. You may use following sample code.
         */
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet hit</title>");            
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet hit at " + request.getContextPath() + "</h1>");
        out.println("</body>");
        out.println("</html>");
    } finally {            
        out.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 {
    PrintWriter out=response.getWriter();
    String Id=request.getParameter("id");
    String Name=request.getParameter("name");
    String Home=request.getParameter("home");
    String Location=request.getParameter("location");
    String Gender=request.getParameter("sex");
    String Choice=request.getParameter("choice");

    try{
     Class.forName("com.mysql.jdbc.Driver");
     Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/location", "root", "root");
    String sql="INSERT INTO posting (ignite_id,name,home,location,gender,choice) VALUES('"+Id+"','"+Name+"','"+Home+"','"+Location+"','"+Gender+"','"+Choice+"')";
  PreparedStatement ps=(PreparedStatement) con.prepareStatement(sql);
    ps.executeUpdate();
    ps.close();
    con.close();



    }
    catch(Exception e)
    {
        out.print(e.toString());
    }
    finally{
        out.print("Submit Successfully");
    out.close();

    }
}

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

}









Related Tutorials/Questions & Answers:
my answer
my answer  import com.mysql.jdbc.Connection; import com.mysql.jdbc.Statement; import java.io.IOException; import java.io.PrintWriter; import java.sql.DriverManager; import java.sql.ResultSet; import
to know my answer
to know my answer  hi, this is pinki, i can't solve my question "how to change rupee to dollar,pound and viceversa using wrapper class in java." will u help me
Advertisements
plz. answer my ques - Java Beginners
plz. answer my ques  I want to ask a prog. prob which would create a prog that would simply take username and password as input and will display ***** while taking passwords as input.(As it is done at login in websites). Also
Clarify my last question's answer - Java Beginners
Clarify my last question's answer  Dear expert, I've tried out... did not specify my question too clearly. Here's my 2 database... and parents contain other fields like name, address, email, contact numbers etc. My
answer it soon
answer it soon  write a proggram to accept a number and check whether the sum of prime factors of a number is a prime number
ModuleNotFoundError: No module named 'answer'
ModuleNotFoundError: No module named 'answer'  Hi, My Python... 'answer' How to remove the ModuleNotFoundError: No module named 'answer'... to install padas library. You can install answer python with following command
ModuleNotFoundError: No module named 'answer'
ModuleNotFoundError: No module named 'answer'  Hi, My Python... 'answer' How to remove the ModuleNotFoundError: No module named 'answer'... to install padas library. You can install answer python with following command
ModuleNotFoundError: No module named 'answer'
ModuleNotFoundError: No module named 'answer'  Hi, My Python... 'answer' How to remove the ModuleNotFoundError: No module named 'answer'... to install padas library. You can install answer python with following command
answer
java.please answer this...
java.please answer this...   Q1).How we can write a complete JAVA program that computes the following summation formulas..? â??_(i=1)^nâ??ã??i^2=ã?? (n^(2 ) ã??(n+1)ã??^2)/4
Answer for SCJP Module-1 Question-13
Answer for SCJP Module-1 Question-13  The Answer for SCJP Module-1 Question-13 is missing , I think the answer is option '1', Correct me if I am wrong
pls answer the Trangle pattern
pls answer the Trangle pattern    a b c d e b c d e c d e d e e Please answer and give the code for above triangle
Urgent Answer Req
Urgent Answer Req  how to view the file content which is at client side from jsp in java
Is the answer 35, 35?
Is the answer 35, 35?  int a = 5; int b = 7; int num = 35; while (a < b) { System.out.println(?My age is ? + num); a = a + 1; }   ...) { System.out.println("?My age is ? "+ num); a = a + 1
please answer me
please answer me  iam using html in select tag.in this one option i selected and that option data will be display in table.And use servlet with html and how to retrieve the data from data base
Please give me the answer.
"int a=08 or 09" its giving compile time error why   "int a=08 or 09" its giving compile time error why ? can any one give me the answer of this please
share your answer to this question
share your answer to this question  i need to know what is the TELERIK CONTROL? what is the map suite? what is dunda chart? Also i have to know what are the websites available which give infor regarding this. Let me know how
pls answer these question
pls answer these question  Write a program that prompts the user to input the length and width of a rectangle. Then calculate and prints the rectangleâ??s area and perimeter.   import java.io.*; class rectangle
answer me this program
answer me this program  Java Code to Maintain student record,Name, Age, Marks of 5 subjects for a Student,Display Student age and name,Calculate Average of all marks and display it   Java student record import
answer me this program
answer me this program  Java Code to Maintain student record,Name, Age, Marks of 5 subjects for a Student,Display Student age and name,Calculate Average of all marks and display it   Java student record import
plz give me answer plz
plz give me answer plz  writw a programme to find rank from an array using doubledimmensionalarray
please send me the answer - JDBC
please send me the answer -difference between DriverManager and DataDourse   what is Datasourse? What r the advantages? what is the difference between DriverManager and DataDourse
Please answer me - JSP-Servlet
Please answer me  Hello Guys, this is the third time I'm sending this question. But I've not got the right answer from you. The again is: I need java servlet or jsp codes that I can use to insert and retrieve image from MSSQL
Plz send me answer quckly
Plz send me answer quckly  Respected Sir, myself is pavan shrivastava.i want ask a question that is ( we can't create object of interface then how would possible to create object
answer this qs in 5 mins plss
answer this qs in 5 mins plss  Create an Web Application, which allows a user to search a book as follows: Based on ISBN code, if he is aware of the code (or) Based on the Book Categories (adsbygoogle
i cNT GET ANSWER FOR THIS QUESTION
i cNT GET ANSWER FOR THIS QUESTION  The roots of the quadratic equation ax2+bx+c=0, aïâ??¹0 are given by the following formula: x=(-bÃ?±âË?Å¡(b^2-4ac))/2a In this formula. The term b2-4ac is called
What is the answer and how the program work?
What is the answer and how the program work?  public class Threads2 implements Runnable { public void run() { System.out.println("run."); throw new RuntimeException("Problem"); } public static void main(String[] args
ModuleNotFoundError: No module named 'odoo10-addon-website-crm-quick-answer'
ModuleNotFoundError: No module named 'odoo10-addon-website-crm-quick-answer'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'odoo10-addon-website-crm-quick-answer' How
ModuleNotFoundError: No module named 'odoo12-addon-website-crm-quick-answer'
ModuleNotFoundError: No module named 'odoo12-addon-website-crm-quick-answer'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'odoo12-addon-website-crm-quick-answer' How
ModuleNotFoundError: No module named 'odoo8-addon-website-crm-quick-answer'
ModuleNotFoundError: No module named 'odoo8-addon-website-crm-quick-answer'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'odoo8-addon-website-crm-quick-answer' How
ModuleNotFoundError: No module named 'odoo9-addon-website-crm-quick-answer'
ModuleNotFoundError: No module named 'odoo9-addon-website-crm-quick-answer'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'odoo9-addon-website-crm-quick-answer' How
My SQL
My SQL  Connection class for MySQL in java
my question
my question   "Write a C/C++ program to show the stored procedure PROCRESETMAIL" on database "USER_NOTIFY
my question
my question   "Write a C/C++ program to show the stored procedure PROCRESETMAIL" on database "USER_NOTIFY
my project
my project   how to creat a e learnig site with student information , faculty details , student queries , student feedback, course information
my assignment
my assignment  as programmer, you have been assigned to develop a user interface for a fats food ordering system.the interface should have various......this is my assignment....plz
java interview question and answer - Java Interview Questions
java interview question and answer   sir, i want one mark java interview question and answers
Please , can any one answer this Question?
Please , can any one answer this Question?  How to cummunicate one web application to another web application in different places
how to get following answer in turbo c program
how to get following answer in turbo c program  input 123456789 output 1 2 3 4 5 6 7 8 9
Answer me ASAP, Thanks, very important
Answer me ASAP, Thanks, very important  Sir, how to fix this problem in mysql i have an error of "Too many connections" message from Mysql server,, ASAP please...Thanks in Advance
please i want someone to answer me pleeeeeeeeeeeeease...
please i want someone to answer me pleeeeeeeeeeeeease...    Write a JAVA program using 2D array to auto-grade exams. For a class of N students, your... answer key as Final Array in your program.( using 2D array
need answer
give answer
send answer
how the answer is 13 can anyone explain plz
how the answer is 13 can anyone explain plz  public class that { public static void main(String arr[]) { int i=3; int j=1; while(i<4) { //j=i; i=i+j/2; } System.out.println(i
help i want it now the answer pleas...
help i want it now the answer pleas...  write a program that will display the exactly output as below: Hints: declare and initialize value of array in double type.Read and write all elements of array.perform the multiply
My-BIC
My-BIC       This is a basic state of mind system rather than a framework Allows you to focus on making things happen rather than setting things up Support for XML, JSON and TEXT ajax
Java experts.Please answer this question - Java Beginners
Java experts.Please answer this question  class A { void get() { System.out.println("A's method"); } } class C extends A{} class D extends A { void set() { System.out.println("D's method"); } } class ins { public
need the answer vry urgently..plz help me...[plzzzzzzzz
need the answer vry urgently..plz help me...[plzzzzzzzz  the question is.... 1-create a form accepting user name,password and confirm password......to [email protected]/[email protected] plz...help....me..it can change my lyfe
How can I to my database to my application
How can I to my database to my application  How can I to my database to my application   Hi, Please see the JDBC discussion thread.ADS_TO_REPLACE_1 Thanks

Ads