Home Answers Viewqa JSP-Servlet Doubt in servlets

 
 


sateeshvaddada
Doubt in servlets
2 Answer(s)      3 years and 3 months ago
Posted in : JSP-Servlet

Good Evening sir/madam,
I want to add data dynamically for that which methods i have to use to retrieve the dynamic data .
View Answers

February 8, 2010 at 5:03 PM


Hi Friend,

Try the following code:

1)get.jsp:
<html>
<form method="post" action="../InsertAndRetrieveData">
<table>
<tr><td>Enter Name:</td><td><input type="text" name="name"></td></tr>
<tr><td>Enter Address:</td><td><input type="text" name="address"></td></tr>
<tr><td><input type="submit" value="Submit"></td></tr>
</table>
</form>
</html>

2)InsertAndRetrieveData.java:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;

public class InsertAndRetrieveData extends HttpServlet{
public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
String name=req.getParameter("name");
String address=req.getParameter("address");

try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root","root";);
Statement st=con.createStatement();
int i=st.executeUpdate("insert into data(name,address) values('"+name+"','"+address+"')");
st.close();
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("Select * from data");
while(rs.next()){
out.println(rs.getString("name")+" "+rs.getString("address")+"<br>");
}
st.close();
}
catch(Exception e){}
}
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{doPost(req,res);}
}

Thanks

February 8, 2010 at 5:04 PM


For more information,visit the following link:

http://www.roseindia.net/servlets/index.shtml

Thanks









Related Pages:
Doubt in servlets - JSP-Servlet
Doubt in servlets  Good Evening sir/madam, I want to add data dynamically for that which methods i have to use to retrieve... the following link: http://www.roseindia.net/servlets/index.shtml Thanks
doubt this
doubt this  what is the use of "this" and "super" keyword
DOUBT ?
DOUBT ?  in c++ member function of a class must be public
Doubt
Doubt  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details
Doubt
User request form  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action="page2.html
Doubt
How to load page  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action="page2.html
Doubt
Submit and process form  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action
Doubt
load next page after submitting  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action
servlet doubt - Servlet Interview Questions
through the following link: http://www.roseindia.net/servlets/servlet-read
java-servlets - JSP-Servlet
java-servlets  I have one doubt.if we update resume in jobportal websites, at that place i saw only some fields are possible to edit at a time. how is it possible. pls clarify my doubt any one. I will be thankful to you
jsp,servlets - JSP-Servlet
jsp,servlets   Good Afternoon Sir, I am sowmya i have a doubt that is whether it is possible to use arrays in servlets.how to declare that arrays in servlets and i am getting values from textbox in jsp
java Servlets - JSP-Servlet
java Servlets  Hi i am having a doubt regarding servlets as i am in learning stage give me any clew how to retrive data from mysql database after getting data from db and again i have to add that data to textbox using html
servlets
servlets  why we are using servlets
servlets
servlets  what is the duties of response object in servlets
servlets
what are advantages of servlets  what are advantages of servlets   Please visit the following link: Advantages Of Servlets
Servlets
Servlets  How to edit and delete a row from the existing table in servlets
servlets
servlets  How do you communicate between the servlets?   We can communicate between servlets by using RequestDespatcher interface and servlet chaining
servlets
what is the architecture of a servlets package  what is the architecture of a servlets package   The javax.servlet package provides interfaces and classes for writing servlets. The Servlet Interface The central
Servlets
Servlets  How to check,whether the user is logged in or not in servlets to disply the home page
servlets
servlets  why we require wrappers in servlets? what are its uses? Please explain   These wrappers classes help you to modify request...://www.roseindia.net/servlets/response-filte.shtml
Servlets
. Anyways, please visit the following links: http://www.roseindia.net/servlets/introductiontoconfigrationservlet.shtml http://www.roseindia.net/servlets
servlets
servlets  How to open and read the contents of a text file in servlets?   Please visit the following link: Read text file using Servlet
servlets
servlets   Hi what is pre initialized servlets, how can we achives?   When servlet container is loaded, all the servlets defined in the web.xml file does not initialized by default. But the container receives
servlets
servlets why do we need web-inf directory in web application  why do we need web-inf directory in web application? means what's the benefits of doing so
Servlets and
Servlets and   Sir...! I want to insert or delete records form oracle based on the value of confirm box can you please give me the idea.... thanks
servlets
which are the differ ways you can communicat between servlets  which are the differ ways you can communicat between servlets   Different ways of communicating between servlets:- 1)Using RequestDispatcher object. 2
servlets
what are sessions in servlets  what are sessions in servlets   A Session refers to all the request that a single client makes to a server...: http://roseindia.net/jsp/jspsession/ http://www.roseindia.net/servlets
servlets
package supports the development of servlets that use the HTTP protocol. The classes... javax.servlet.GenericServlet and serves as the base class for HTTP servlets. HttpServlet-Request
the servlets
what is diff between generic servlets and httpservlets  what is diff between generic servlets and httpservlets   Difference between GenericServlet and HTTPServlet: 1)GenericServlet belongs to javax.servlet package
servlets
regarding the user usage and habits. Servlets sends cookies to the browser client...://www.roseindia.net/jsp/jspcookies.shtml http://www.roseindia.net/servlets/use
servlets
servlets  hi i am using servlets i have a problem in doing an application. in my application i have html form, in which i have to insert on date value, this date value is retrieved as a request parameter in my servlet
servlets
servlets  what are different authentication options available in servlets   There are four ways of authentication:- HTTP basic authentication HTTP digest authentication HTTPS client authentication Form-based
servlets
what are filters in java servlets  what are filters in java   Filters are powerful tools in servlet environment. Filters add certain functionality to the servlets apart from processing request and response paradigm

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.