Question: jsp

Ads

 
 
 

Share on Google+Share on Google+

prathima
jsp
2 Answer(s)      7 years ago
Posted in : Java Beginners
Ads
View Answers

December 22, 2009 at 12:21 PM


Hi Friend,

Try the following code:
1)display.jsp:

<[email protected] import="java.sql.*"%>
<h2>Patients List</h2>
<form name=myname method=post action="post.jsp">
<table border="1">
<tr><td></td>
<th>No</th>
<th>Name</th>
<th>Address</th>
<th>Disease</th>
<th>Contact No</th>
<th>Prefer To</th>
</tr>
<%try{

Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root";, "root");
ResultSet rs = null;
Statement st=null;
st=conn.createStatement();
rs = st.executeQuery("select * from medical");
int i=0; while(rs.next()){ %>
<tr><td><input type="checkbox" name="check<%=i%>" value=<%= rs.getString("id") %>></td>
<td><%= rs.getString("id") %></td>
<td><%= rs.getString("name") %></td>
<td><%= rs.getString("address") %></td>
<td><%= rs.getString("disease") %></td>
<td><%= rs.getString("contactNo") %></td>
<td><select name="doctor">
<option ><-Select-></option>
<option value="AA">Dr A</option>
<option value="BB">Dr B</option>
<option value="CC">Dr C</option>
<option value="DD">Dr D</option>
</select>
</td>
</tr><%
i++;
}
}catch(SQLException e){ System.out.println(e.getMessage()); } %>
</table>
<input type="submit">
</form>

2)post.jsp:
<[email protected] import="java.sql.*"%>
<h2>Send Details</h2>
<%String id[]= new String[10];
for(int i=0;i<10;i++){
id[i]=request.getParameter("check"+i);
System.out.println(id[i]);
}
String doc[]=request.getParameterValues("doctor");
for(int i=0;i<doc.length;i++){
System.out.println(doc[i]);
}
%>
<form name=myname method=post action="send.jsp">
<table border="1">
<tr>
<th>No</th>
<th>Name</th>
<th>Address</th>
<th>Disease</th>
<th>Contact No</th>
<th>Prefer To</th>
</tr>
<%try{
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root";, "root");
ResultSet rs = null;
Statement st=null;
st=conn.createStatement();
for(int a=0;a<10;a++){
rs = st.executeQuery("select * from medical where id='"+id[a]+"'");
while(rs.next()){ %>
<tr>
<td><input type="text" name="id" value="<%= rs.getString("id") %>"></td>
<td><input type="text" name="name" value="<%= rs.getString("name") %>"></td>
<td><input type="text" name="address" value="<%= rs.getString("address") %>"></td>
<td><input type="text" name="disease" value="<%= rs.getString("disease") %>"></td>
<td><input type="text" name="contactNo" value="<%= rs.getString("contactNo") %>"></td>
<td><input type="text" name="doctor" value="<%=doc[a]%>"></td>

</tr><%
}
}
}catch(SQLException e){ System.out.println(e.getMessage()); } %>
</table>

<input type="submit">
</form>


December 22, 2009 at 12:25 PM


continue...

3)send.jsp:

<[email protected] import="java.sql.*"%>
<%
String d[] =request.getParameterValues("id");
if(d !=null) {
for(int i=0;i<d.length;i++) {
//out.println(d[i]);
}
}
String name[] =request.getParameterValues("name");
if(name !=null) {
for(int i=0;i<name.length;i++) {
//out.println(name[i]);
}
}
String address[] =request.getParameterValues("address");
if(address !=null) {
for(int i=0;i<address.length;i++) {
//out.println(address[i]);
}
}
String disease[] =request.getParameterValues("disease");
if(disease !=null) {
for(int i=0;i<disease.length;i++) {
//out.println(disease[i]);
}
}
String contactNo[] =request.getParameterValues("contactNo");
if(contactNo !=null) {
for(int i=0;i<contactNo.length;i++) {
//out.println(contactNo[i]);
}
}
String doctor[] =request.getParameterValues("doctor");
if(doctor !=null) {
for(int i=0;i<doctor.length;i++) {
//out.println(doctor[i]);
}
}
%>
<%
try{
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root";, "root");
Statement st=conn.createStatement();
ResultSet rs=null;
for(int a=0;a<doctor.length;a++){
String doc=doctor[a];
rs=st.executeQuery("Select * from doctorlist where doctor='"+doc+"'");
String email="";
while(rs.next()){
email=rs.getString("email");
out.println(email);
}
}
}
catch(Exception e){
e.printStackTrace();
}
%>

For the above code, we have used the following tables:

1)CREATE TABLE `doctorlist` (
`id` bigint(255) NOT NULL auto_increment,
`doctor` varchar(255) default NULL,
`email` varchar(255) default NULL,
PRIMARY KEY (`id`)
)
2)CREATE TABLE `medical` (
`id` bigint(30) NOT NULL auto_increment,
`name` varchar(255) default NULL,
`address` varchar(255) default NULL,
`disease` varchar(255) default NULL,
`contactNo` int(255) default NULL,
PRIMARY KEY (`id`)
)

Thanks

Ads









Related Tutorials/Questions & Answers:
jsp
jsp  how to include two jsp page
Jsp
Jsp  Can I implement interface in jsp
Advertisements
jsp
jsp  how to create jsp page
JSP
JSP  How to run jsp program in eclipse
jsp
jsp  how jsp translated into servlets
JSP
what is JSP forward tag for  what is JSP forward tag for   It forwards the current request to another JSP page. Below is the syntax for the same:- <jsp:forward page="...url..." /> We can also forward parameter
jsp
jsp  write a code for jsp file generator to generate a jsp page automatically taking html page as input
jsp
jsp  how to create a table in oracle using jsp and the table name is entered in text feild of jsp page
JSP
JSP  Hi, What is JSP? What is the use of JSP? Thanks   Hi, JSP Stands for Java Server Pages. It is Java technology for developing web applications. JSP is very easy to learn and it allows the developers to use Java
jsp
jsp   what is the basic necessities reguired for running jsp using JDBC bridge?? and how to write a jsp code to access the detail present in microsoft access pls send link regarding above
jsp
jsp  how to connect the database with jsp using mysql   Hi Friend, Please visit the following links: http://www.roseindia.net/jsp/connectjspwith_mysql.shtml http://www.roseindia.net/jsp/Accessingdatabase-fromJSP.shtml
jsp
jsp  how to upload image through csv format in jsp
jsp
jsp  I Want complete note on JSP servlet
jsp
jsp  how to delete data from database using jsp
JSP
JSP  FILE UPLOAD-DOWNLOAD code USING JSP
jsp
jsp  how to write hindi in jsp and store in database as unicode
jsp
jsp  code for jsp automatic genration using html
jsp
jsp  why jsp is translated into servlet?pls describe precisly
JSP
JSP  relevant difference between servlet and jsp in 1 line
jsp
jsp  how to pass jsp variable to an html page
jsp
jsp  how to write a servlet and jsp program for user login form
jsp
jsp  how to write a servlet and jsp program for user login form
JSP
JSP   How to create CAPTCHA creation by using JSP? I need an code for CAPTCHA creation by using JSP...   You can create a captcha validation using jsp. Have a look at the following tutorial: Captcha Creation
jsp
jsp  how to include google map in our jsp page
JSP
What are JSP directives, page directives and include directives?  what are jsp directives? and what are page directives? and what are include directives? can you explain taglib directives?   JSP directives JSP
JSP
Can you explain jsp page life cycle what is el how does el search for an attribute in JSP  Can you explain jsp page life cycle what is el how does el...://www.roseindia.net/jsp/simple-jsp-example/LifeCycleOfJspPage.shtml http
JSP
JSP  what are the different scopes an object can have in a jsp page   JSP Scope Variables: Page scope-It makes the data available... the following links: http://www.roseindia.net/jsp/simple-jsp-example
JSP
what is jstl in JSP   what is jstl   JSTL is also called as JSP tag libraries. They are collection of custom actions which canbe accessed as JSP tags. For more information, visit the following link: JSTL Tutorials
JSP
access application data stored in JavaBeans components. The jsp expression...). Before JSP 2.0, we could use only a scriptlet, JSP expression, or a custom tag to include server state in the jsp page output. For more information, visit
JSP
JSP public opinion poll   Develop a JSP for a news channel to conduct public opinion poll on any topic. Users will respond through yes or no options. Later display the result in percentage
jsp
jsp  sir i want to jsp code for online examination like as bank po,,,,,,plz help me sir
Tutorials   
Java Spring Hibernate Struts Training Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java Java Example Codes and Tutorials in 2017 How do I read a large file quickly in Java? Is learning Java worthwhile? How to create first Java Program? Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include?

Ads

 
Advertisement null

Ads