Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Ajax my answer
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Bipin Kumar Aryan
my answer
1 Answer(s)      a year and 7 months ago
Posted in : Ajax


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>

}


Advertisement
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
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
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
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
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
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
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
My SQL
My SQL  Connection class for MySQL in java
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 The results of the search has
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
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
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
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
 

 

 

DMCA.com