J2EE

J2EE

i want to make use of check box and radio button and i want the details to be submitted into the database server. moreso, i want you to teach me how to use request dispatcher and session object.

thanks
View Answers

February 6, 2010 at 3:51 PM

Hi Friend,

Try the following code:
1)form.jsp:

<html>
<form name="form" action="insert.jsp" method="post">
<table>
<tr><td>Enter Name</td><td><input type="text" name="name"></td></tr>
<tr><td>Enter Address</td><td><textarea rows="4" cols="8" name="address"></textarea></td></tr>
<tr><td>Gender</td><td><input type="radio" name="radio">M<input type="radio" name="radio">F</td></tr>
<tr><td>Qualification</td><td><select name="qua"><option value="BTech">BTech</option><option value="BTech">MBA</option><option value="BTech">MCA</option><option value="BTech">MTech</option></select></td></tr>
<tr><td>Languages</td><td><input type="checkbox" name="lang" value="Hindi">Hindi<input type="checkbox" name="lang" value="English">English<input type="checkbox" name="lang" value="French">French<input type="checkbox" name="lang" value="German">German</td></tr>
<tr><td><input type="submit" value="Submit" ></td><td><input type="reset"></td></tr>
</table>
</form>
</html>

2)insert.jsp:
<%@page import="java.sql.*"%>
<%
String name=request.getParameter("name");
String address=request.getParameter("address");
String g=request.getParameter("radio");
String qualif=request.getParameter("qua");
String languages[]=request.getParameterValues("lang");
String lang="";
for(int i=0;i<languages.length;i++){
lang+=languages[i]+" ";
}
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register";, "root", "root");
Statement stmt = con.createStatement();
int j=stmt.executeUpdate("insert into person1(name,address,gender,qualification,languages) values('"+name+"','"+address+"','"+g+"','"+qualif+"','"+lang+"')");
out.println("Data is inserted sucessfully");
}
catch(Exception e){}
%>

February 6, 2010 at 3:53 PM

continue........

RequestDispatcher:

RequestDispatcher defines an object that receives requests from the client and sends them to any resource (such as a servlet, HTML file, or JSP file) on the server. The servlet container creates the RequestDispatcher object, which is used as a wrapper around a server resource located at a particular path or given by a particular name.

The include method of the RequestDispatcher interface may be called at ANY time. The target servlet of the include method has access to all aspects of the request object, but its use of the response object is more limited. It can only write information to the ServletOutputStream or Writer of the response object and commit a response by writing content past the end of the response buffer, or by explicitly calling the flushBuffer method of the ServletResponse interface. It CANNOT set headers or call any method that affects the headers of the response. Any attempt to do so must be ignored.

The forward method of the RequestDispatcher interface may be called by the calling servlet ONLY when NO output has been committed to the client. If output data exists in the response buffer that has not been committed, the content must be cleared before the target servlet's service method is called. If the response has been committed, an IllegalStateException must be thrown.

For sessions, visit the following link:

http://www.roseindia.net/jsp/jspsession/
http://www.roseindia.net/jsp/

Thanks









Related Tutorials/Questions & Answers:
j2ee
j2ee  what is j2ee
j2ee
j2ee  sir can you give me some of the definitions of project under the platform of j2ee
Advertisements
J2EE
J2EE  What is J2EE?   J2EE is an environment for developing and deploying enterprise applications. The J2EE platform consists of a set of services, application programming interfaces (APIs), and protocols that provide
J2EE
J2EE  what is single table strategy in JPA
j2ee
j2ee  I want program for login page with database connectivity using struts framework. that application should session management and cookies
j2ee
j2ee  I want program for login page with database connectivity using struts framework. that application should session management and cookies
j2ee
j2ee  hi i'm beginner 2 j2ee.. my question is... when user enters his fname,lname,address,city from ui(html) it gets inserted into db...my problem is when user submit without entering i,e blank it also get inserted into db even
j2ee
j2ee  hi i'm beginner 2 j2ee.. my question is... when user enters his fname,lname,address,city from ui(html) it gets inserted into db...my problem is when user submit without entering i,e blank it also get inserted into db even
j2ee
j2ee  hi i'm beginner 2 j2ee.. my question is... (jdbc connecton): when user enters his fname,lname,address,city from ui(html) it gets inserted into db...my problem is when user submit without entering i,e blank it also get
J2EE - JMS
J2EE  hai,This is jagadhish.Iam learning J2EE. I want to know the concept JMS.For that send some data and example programs plz.thank you (in advance
J2EE clients
J2EE clients  What are types of J2EE clients?   Following are the types of J2EE clients: Applets. Application clients. Java Web Start-enabled rich clients, powered by Java Web Start technology. Wireless clients, based
j2ee - Hibernate
j2ee  what is meant by o-r mapping with an example what is the difference between bean,javabean,ejb with an example
j2ee - EJB
j2ee  when we given a request for ejb cointainer how the container calls the we requested method call
j2ee - Struts
j2ee  hi can you explain what is proxy interface in delegater design pattern
J2EE - Date Calendar
J2EE Server List  j2ee server list
J2EE - Struts
J2EE  what is Struts Architecture?  Hi Friend, Please visit the following links: http://www.roseindia.net/struts/StrutsArchitecture.shtml http://www.roseindia.net/struts/struts2/struts-2-architecture.shtml
J2EE Application
J2EE Application  I developed a j2ee application.I used apache tomcat server on my machine and ran it using http://<IPaddressOfMachine>(OR)localhost:8080/<ApplicationName> Its running on my machine fine as well
j2ee - Spring
j2ee  hi guys can any send me the spring mvc example,thanks in advance  Hi Friend, Please visit the following link: http://www.roseindia.net/spring/index.shtml Hope that it will be helpful for you. Thanks
j2ee - Struts
j2ee  How to get values from a database which is stored in form1 in to form2 with in a listbox. pls help me.  Hi bhaskar, You have to write database related code in the form itself in which the list box is present
j2ee - JDBC
J2EE - Counting the number of records in the table  Counting the number of records in the table J2EE  Hi,Are you trying to find the solution for counting the number of records in the table.Suppose you have student table
j2ee - EJB
j2ee  i want to know the ejb 2.0 architecture by diagram and also ejb 3.0 architecture i want to know the flow in ejb 2.0 and ejb 3.0  Hi friend, I am sending you a link. This link will help you. Please visit
J2ee - Hibernate
J2ee  I need to save datas like employee details in database, while saving i am getting exceptioin as org.hibernate.exception.GenericJDBCException: caused by com.microsoft.sqlserver.jdbc.SQLServerException: and an error
j2ee - EJB
j2ee  how can u make a call from session Bean of SessionFacade to Entity Bean when ur using persistence logic implemented in Entity Beans. I think inorder to get the home interface obj for first time it will look up in jndi
j2ee - JDBC
j2ee  how to connect jsp to mysql   Hi, Thanks for asking question. I will tell you how you can connection to MySQL from JSP page. Actually you have to install the MySQL driver in your web application
doubt about J2EE connetivity
doubt about J2EE connetivity  steps to connect J2EE components with MYSQL
J2EE - Java Beginners
J2EE Programming  What i need to learn to start programming in J2EE
Components of J2EE application
Components of J2EE application  What are the components of J2EE application
j2ee - Java Beginners
j2ee  class one
j2ee - JSP-Servlet
j2ee  What is session
j2ee - JDBC
j2ee  import java.sql.*; public class Sample1 { public static void main(String args[])throws Exception { Class.forName("Oracle.jdbc.driver.OracleDriver"); Connection con=DriverManager.getConnection("jdbc:oracle
j2ee hibernate
In this section you will learn about hibernate for j2ee
j2ee text book
j2ee text book  what is the best book for learning j2ee with examples in weblogic server with (netbeans or eclipse
about J2EE. - Java Beginners
about J2EE.  I know only core Java ... what chapter I will be learn to know about J2EE
J2EE - Java Interview Questions
J2EE  How do we call destroy() in service
J2EE - Java Interview Questions
J2EE  How do we call destroy() in service
j2ee - Java Beginners
j2ee  why we are using the j2ee?   Hi friend, J2EE Stands for Java 2 Enterprise Edition. J2EE is an environment for developing and deploying enterprise applications. J2EE specification is defined by Sun
j2ee - Java Server Faces Questions
J2EE EAR Structure   What is the structure for J2EE EAR
about J2EE. - Java Beginners
about J2EE.  I know only core Java ... what chapter I will be learn to know about J2EE.  Hi Friend, Please visit the following link: http://www.roseindia.net/ Thanks
what is the difference in java and j2ee
what is the difference in java and j2ee  Hi, Please tell me: 1. What is the difference between Java and Core Java and 2. Difference between Java and J2EE
J2EE - Java Beginners
J2EE  Please give me name of "AT command" for sending wave file via mobile
Are J2EE and Java Advanced the same?
Are J2EE and Java Advanced the same?  Hi, I am checking J2EE and Advanced Java. Are J2EE and Java Advanced the same? Thanks   Hi, J2EE is now renamed to JEE in latest version of Java platform, which is Specification
Basic on J2ee - Java Beginners
Basic on J2ee  J2EE is a platform that helps us to develop and deploy... be executed, it must be configured as j2ee service and deployed into its container." What does configure as j2ee service mean ?? Do the application need
j2ee - Development process
J2EE Development Process   What is mean by J2EE Development process?  hi bhuvana,i think i may answer ur ques.see i can tell u in java script if u needed
j2ee - Java Beginners
J2EE count records in table  How to count the number of records in a table in my J2EE application?  Hi,Are you using jsp page?Thanks  yes i am using jsp page  I haven't receive ur answer
j2ee example programs
j2ee example programs   can any one tell me how to develop and execute ---------- j2ee entity beans (cmp,bmp) example,message driven bean example ,webservices example in weblogic server with (netbeans or eclipse
j2ee - JSP-Servlet
j2ee  how upload a file in database and store the file in a separete directory and can read the file when ever we want(SOURCE CODE
j2ee - Java Interview Questions
j2ee  what are the services does the weblogic server provide in project development OR what are the services we take from the weblogic during project development
J2EE - Java Beginners
J2EE  Dear Sir, Right now i am working as a java programmer and i have to learn for J2EE. Which book is good for learning JSP, SERVLETS,EJB... in J2EE and the companies asking which technology mostly and which technology i have
J2EE - Java Interview Questions
J2EE  What is J2EE architecture?  Hi friend, The Java? 2 Platform, Enterprise Edition (J2EE) provides a standard for developing... solutions. The J2EE specification satisfies these challenges by providing
j2ee - JSP-Servlet
j2ee  Hello, Could please anybody tell me that can we run a servlet through the command prompt? If so what is the process.Please tell me

Ads