convert jsp to servlet

Ads
 

convert jsp to servlet

how to convert following code into servlet

int i=0;
while(rs.next())
{
%>
<tr>
    <td>
        <input type="checkbox" name="check<%=i%>" value=<%= rs.getString("bookid") %>>
    </td>

    <td>
        <%= rs.getString("bookid") %></td><td><%= rs.getString("author") %>
    </td>

        <td>
            <%= rs.getString("title") %>
        </td>

    </tr>

    <%i++; 
View Answers

April 23, 2012 at 6:03 PM

Here is your required code:

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Servlet extends HttpServlet{ 
  public void doGet(HttpServletRequest request, 
  HttpServletResponse response)
  throws ServletException,IOException{
  response.setContentType("text/html");
  PrintWriter out = response.getWriter();
   response.setContentType("text/html");
   out.println("<form name=myname method=post action=edit.jsp><table border=1><tr><td></td><td><b><u>bookid</u></b></td><td><b><u>Author</u></b></td><td><b><u>title</u></b></td></tr>");
   try{

Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://192.168.10.112:3306/mysql","root", "root");
ResultSet rs = null;
Statement st=null;
st=conn.createStatement();
rs = st.executeQuery("select * from book");
int i=0; 
while(rs.next()){
    out.println("<tr><td><input type=checkbox name=check"+i+" value="+rs.getString("bookid")+"></td><td>"+rs.getString("bookid")+"</td><td>"+rs.getString("author")+"</td><td>"+rs.getString("title")+"</td></tr>");
i++;
}
}
catch(SQLException e){
    System.out.println(e.getMessage());
    }
    out.println("</table><input type=submit></form></html>");
  }
}

April 23, 2012 at 6:03 PM

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Servlet extends HttpServlet{ 
  public void doGet(HttpServletRequest request, 
  HttpServletResponse response)
  throws ServletException,IOException{
  response.setContentType("text/html");
  PrintWriter out = response.getWriter();
   response.setContentType("text/html");
   out.println("<html><form name=myname method=post action=edit.jsp><table border=1><tr><td></td><td><b><u>bookid</u></b></td><td><b><u>Author</u></b></td><td><b><u>title</u></b></td></tr>");
   try{

Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://192.168.10.112:3306/mysql","root", "root");
ResultSet rs = null;
Statement st=null;
st=conn.createStatement();
rs = st.executeQuery("select * from book");
int i=0; 
while(rs.next()){
    out.println("<tr><td><input type=checkbox name=check"+i+" value="+rs.getString("bookid")+"></td><td>"+rs.getString("bookid")+"</td><td>"+rs.getString("author")+"</td><td>"+rs.getString("title")+"</td></tr>");
i++;
}
}
catch(SQLException e){
    System.out.println(e.getMessage());
    }
    out.println("</table><input type=submit></form></html>");
  }
}

Ads









Related Tutorials/Questions & Answers:
convert jsp to servlet
convert jsp to servlet  how to convert following code into servlet int i=0; while(rs.next()) { %> <tr> <td> <input type="checkbox" name="check<%=i%>" value=<%= rs.getString("bookid
servlet and jsp
servlet and jsp  how to connect an jsp and an servlet without connecting to database
Advertisements
Servlet - JSP-Servlet
Servlet and Java Code  Example and source code in Servlet and JSP
Servlet - JSP - JSP-Servlet
Servlet - JSP  i used arraylist in servlet as shown ArrayList total = new ArrayList (); ... total.add(k[i]); session.setAttribute("efg",total); when I code this like in my jsp <%ArrayList<Integer> data= new
Servlet - JSP - JSP-Servlet
Servlet - JSP  Here is my complete code. all my code is running with out any error. the for loop in servlet is running as many times as my checkboxes... Servlet Code: ---------------------- package com.servlet; import
jsp servlet
jsp servlet  i dont know how to write a code to Create a JSP with one text field to enter the URL and a submit button.On clicking the submit button, send the request to a servlet .Once the servlet receives the request, it need
jsp servlet
jsp servlet  i dont know how to write a code to Create a JSP with one text field to enter the URL and a submit button.On clicking the submit button, send the request to a servlet .Once the servlet receives the request, it need
JSP-Servlet
JSP-Servlet  Hi have created a JSP page and I need to print it when the user clicks on the print button. I have put a print button on the JSP page. Can somebody plz help me out with the Servlet page coding
jsp and servlet
the data and delete the data,using jsp and servlet...jsp and servlet  I want to create a login form,which have many fields,and have a connectivity with thwe oracle database,and login form will have
jsp and servlet
jsp and servlet  hello friends just want to create a jsp page... login from login page and if we submit it shud be validated in a servlet using... links: http://www.roseindia.net/jsp/loginbean.shtml http://www.roseindia.net
jsp servlet
code to Create a JSP with one text field to enter the URL and a submit button  i dont know how to write a code to Create a JSP with one text field... the request to a servlet .Once the servlet receives the request, it need to create
jsp servlet
how to write a code to Create a JSP with one text field to enter the URL  i dont know how to write a code to Create a JSP with one text field... to a servlet .Once the servlet receives the request, it need to create a thread
servlet and jsp
servlet and jsp  how can i get a form question from a database... with servlets and jspīs   Have a look at the following links: http://www.roseindia.net/jsp/paging.shtml http://www.roseindia.net/jsp/navigation
How to call servlet in JSP?
How to call servlet in JSP?  How to call servlet in JSP
jsp servlet
jsp servlet  dispay hindi in jsp
Java Servlet - JSP-Servlet
Java Servlet   Hello Sir Could you help me in understanding directory Structure for servlet page in eclipse (IDE). I save my Sevlet in WEB-INF but it is not displaying, it is displaying code of servlet. Process used
jsp and servlet
jsp and servlet  If i want to get dynamic value in html textbox or in jsp,then how can I get the value,how the value will be transfered from servlet... javax.servlet.*; import javax.servlet.http.*; public class Servlet extends
calling servlet from jsp
calling servlet from jsp  how to call a servlet from jsp
Servlet Question - JSP-Servlet
Servlet Question  I want to call one servlet when the browser window is closed by User
Servlet Question - JSP-Servlet
Servlet Question  I want to call one servlet when the browser window is closed by User
SERVLET AND JSP
SERVLET AND JSP  If i want tio create a login form using SUBMIT,ADD...;For more information visit the following links: http://www.roseindia.net/jsp/user...://www.roseindia.net/answers/viewqa/JSP-Servlet/16413-using-insert-and-delete-in-a-single
SERVLET AND JSP
SERVLET AND JSP  If i want tio create a login form using SUBMIT,ADD...;For more information visit the following links: http://www.roseindia.net/jsp/user...://www.roseindia.net/answers/viewqa/JSP-Servlet/16413-using-insert-and-delete-in-a-single
how to convert jsp to exe
how to convert jsp to exe  hello sir, i am doing... tomcat5.0,j2se5.0 and jsp,servlets i am using.this is doing in localhost only. now i want... to another system. so i want to convert this to exe. that will executed only internet
EL in jsp - JSP-Servlet
. The default mode for JSP pages delivered using a Servlet 2.3 or earlier descriptor... for JSP pages delivered with a Servlet 2.4 descriptor is to evaluate EL...EL in jsp  hai, I tried to test EL operators in my jsp i
jsp program - JSP-Servlet
jsp program  1.write a servlet program that finds out the given... an application in jsp to redirect the request to any other page.  Hi Friend...,please go through the following link: http://www.roseindia.net/jsp/jsp
Servlet,Jsp
Servlet,Jsp   This is my requirement?I have a login page and register page?If I give the url as http://localhost:8080/Project/Login.jsp ,it should go to login page?.then from login page on click of register button I can register
JSP-Servlet
JSP-Servlet  Hi , I have a table and a checkbox box in that. If i select a particular checkbox, then the particular row details has to be fetched and should be given to two buttons..i/e. when i click on a checkbox, two buttons
jsp servlet
jsp servlet  i have to create one application in which at one page login id will be entered and after entering it will go to second page where first name,last name, date of birth has to be filled and save buttom has to be pressed
Jsp servlet
Jsp servlet  Hai , i want add image details to database how ,please help   Here is a jsp code that allow the user to select the file and and upload it, then save it to database with some details like file path
JSP AND SERVLET
JSP AND SERVLET  I want to create a login form with user name and password field,if the user is new then s/he can click on the new user hyperlink and new page will be display,and data will be updated to the database successfully
java - JSP-Servlet
java  why is required to write both jsp and servlet in a application of java

Ads