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



Home Answers Viewqa JSP-Servlet Doubt in servlets

Have Programming Question? Ask it here!
 
 
 


sateeshvaddada
Doubt in servlets
2 Answer(s)      4 years and 6 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 .

Advertisement
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 Tutorials/Questions & Answers:
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
Advertisements
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
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
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
servlets
servlets  what is the duties of response object in servlets
servlets
servlets  why we are using 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 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
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
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
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
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
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
Validation doubt
Validation doubt  hi..... thanks for the other validation code. I have got that and implemented in my code but i have a doubt in that. As we try... think i am able to tell u what i want to and u have got whats my doubt. plz give
doubt on DAO's
doubt on DAO's  hai frnds.... can anyoneexplain about how to integrate struts with hibernate,any predifined plugin is available or we need to create our own plugin????? and please help me. how to use dao s while integrating
doubt on DAO's
doubt on DAO's  hai frnds.... can anyoneexplain about how to integrate struts with hibernate,any predifined plugin is available or we need to create our own plugin????? and please help me. how to use dao s while integrating
java beginners doubt!
java beginners doubt!  How to write clone()in java strings
doubt about J2EE connetivity
doubt about J2EE connetivity  steps to connect J2EE components with MYSQL
doubt in struts - Struts
doubt in struts   i don't understand the concept on Resource bundle in struts can u please help me out
doubt regarding JSF
doubt regarding JSF  Hi, pls explain what is difference between struts &JSF? pls explain what is difference between SPRING &JSF
String doubt replace function
String doubt replace function  What is the output and why of below : String s1 = "Hello"; if(s1.replace('H','H')== "Hello") System.out.println("yes"); else System.out.println("No"); if(s1.replace("H", "H")== "Hello
Doubt Regarding Charts
Doubt Regarding Charts  Hi, Can you please help me out by answering "hoe to include charts in core java code and struts code" thanks in advance, Swaroop Eswara   Please visit the following link: Jfreechart
"Doubt on Swing" - Java Beginners
"Doubt on Swing"  Hi Friend.... Thanks for ur goog Response.. i need to create a GUI Like... pic1.gif RadioButton pic2.gif RadioButton Pic3.gif RadioButton If we have select d appropriate radio
DOubt in Mysql connections
DOubt in Mysql connections  i have some problem regarding data base connections, i have created a hostname, username and password in filezilla server but after i give those names also it is showing error like this: mysql
Doubt regarding charts and jsp
Doubt regarding charts and jsp  Hi, I successfully executed the bar chart in normal java application. But I want the Bar Chart to be executed in web application(jsp). So,please help me out in how to connect the normal
Doubt regarding charts and jsp
Doubt regarding charts and jsp  Hi in the http://www.roseindia.net/chartgraphs/barchart-jsppage.shtml of the code (new StandardEntityCollection()); final File file1 = new File("../webapps/jspchart/web/barchart.png
Doubt on Segmentation - Java Beginners
Doubt on Segmentation  Hi .. ImageProcessing.. How to segment the each and every characters from the bitmap image Consider for an example bitmap1.bmp: Visuallc++ text is on bitmap1.bmp..How to extract those from image
Advertisements
 

 

 

DMCA.com