how to use a single web page multiple functionaliteies

how to use a single web page multiple functionaliteies

i have a web page in that according to user role functionality should be varies/changes but page should be common for every user & functionality..my moto is to reduse the web pages & code...

View Answers

February 23, 2012 at 5:17 PM

1)application.jsp:

<%@ page import="java.sql.*" %>
<html>
<head>
<script language="javascript">
function editRecord(id){
    var f=document.form;
    f.method="post";
    f.action='edit.jsp?id='+id;
    f.submit();
}
function deleteRecord(id){
    var f=document.form;
    f.method="post";
    f.action='delete.jsp?id='+id;
    f.submit();
}
</script>
</head>
<body>

<br><br>
<form method="post" name="form">
<table border="1">
<tr><th>Name</th><th>Address</th><th>Contact No</th><th>Email</th></tr>
<%
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "test";
String driver = "com.mysql.jdbc.Driver";
String userName ="root";
String password="root";

int sumcount=0;
Statement st;
try{
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+db,userName,password);
String query = "select * from employee";
st = con.createStatement();
ResultSet rs = st.executeQuery(query);
%>

<%
while(rs.next()){
%>
<tr><td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
<td><%=rs.getString(5)%></td>
<td><input type="button" name="edit" value="Edit" style="background-color:#49743D;font-weight:bold;color:#ffffff;" onclick="editRecord(<%=rs.getString(1)%>);" ></td>
<td><input type="button" name="delete" value="Delete" style="background-color:#ff0000;font-weight:bold;color:#ffffff;" onclick="deleteRecord(<%=rs.getString(1)%>);" ></td>
</tr>
<%
}
%>
<%
}
catch(Exception e){
e.printStackTrace();
}
%>
</table>
</form>
</body>
</html>

2)edit.jsp:

<%@page language="java"%>
<%@page import="java.sql.*"%>
<form method="post" action="update.jsp">
<table border="1">
<tr><th>Name</th><th>Address</th><th>Contact No</th><th>Email</th></tr>
<%
String id=request.getParameter("id");
int no=Integer.parseInt(id);
int sumcount=0;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
String query = "select * from employee where id='"+no+"'";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next()){
%>
<tr>
<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="contact" value="<%=rs.getInt("contactNo")%>"></td>
<td><input type="text" name="email" value="<%=rs.getString("email")%>"></td>
<td><input type="hidden" name="id" value="<%=rs.getString(1)%>"></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Update" style="background-color:#49743D;font-weight:bold;color:#ffffff;"></td>
</tr>
<%
}
}
catch(Exception e){}
%>
</table>
</form>
</form>

February 23, 2012 at 5:18 PM

continue....

3)update.jsp:

<%@page import="java.sql.*"%>

<%
String ide=request.getParameter("id");
int num=Integer.parseInt(ide);
String name=request.getParameter("name");
String address=request.getParameter("address");
int contact=Integer.parseInt(request.getParameter("contact"));
String email=request.getParameter("email");
try{
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");
Statement st=null;
st=conn.createStatement();
st.executeUpdate("update employee set name='"+name+"',address='"+address+"',contactNo="+contact+",email='"+email+"' where id='"+num+"'");
response.sendRedirect("/examples/jsp/application.jsp");
}
catch(Exception e){
System.out.println(e);
    }
%>

4)delete.jsp:

<%@page import="java.sql.*"%>
<%

String id=request.getParameter("id");
int no=Integer.parseInt(id);
int sumcount=0;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st = conn.createStatement();
st.executeUpdate("DELETE FROM employee WHERE id = '"+no+"'");
response.sendRedirect("application.jsp");
}
catch(Exception e){}
%>









Related Tutorials/Questions & Answers:
how to use a single web page multiple functionaliteies
how to use a single web page multiple functionaliteies  i have a web page in that according to user role functionality should be varies/changes but page should be common for every user & functionality..my moto is to reduse
how to use a single web page multiple functionaliteies
how to use a single web page multiple functionaliteies  i have a web page in that according to user role functionality should be varies/changes but page should be common for every user & functionality..my moto is to reduse
Advertisements
how to use a single web page multiple functionaliteies
how to use a single web page multiple functionaliteies  i have a web page in that according to user role functionality should be varies/changes but page should be common for every user & functionality..my moto is to reduse
how to use a single web page multiple functionaliteies
how to use a single web page multiple functionaliteies  i have a web page in that according to user role functionality should be varies/changes but page should be common for every user & functionality..my moto is to reduse
how to use a single web page multiple functionaliteies
how to use a single web page multiple functionaliteies  i have a web page in that according to user role functionality should be varies/changes but page should be common for every user & functionality..my moto is to reduse
how to use a single web page multiple functionaliteies
how to use a single web page multiple functionaliteies  i have a web page in that according to user role functionality should be varies/changes but page should be common for every user & functionality..my moto is to reduse
multiple dropdowns in single page - JSP-Servlet
multiple dropdowns in single page  i have a jsp page having drop down menus generated based on the number of request send and name of the drop down... run the page only first id is getting modified can any one help me Thanks
how insert multiple images in mysql database with use of struts 1.3.8 or java method, with single bean,or using array
how insert multiple images in mysql database with use of struts 1.3.8 or java method, with single bean,or using array  i am using netbeans 7.0 ,with struts 1.3.8 and i want to insert multiple images in mysql database ,with use
multiple submits, single form.
multiple submits, single form.  is it possible to use multiple submit buttons in a single form?   Thank you
all sequences to create jdbc and how can i use jtable to display a single columns or multiple columns
all sequences to create jdbc and how can i use jtable to display a single columns or multiple columns  i am 3rd year cs student in ethiopia. i have a view in my database schema so how can i create a jtable to look the view result
Use multiple catch statement in single jsp
Use multiple catch statement in single jsp       In java a single try can have multiple... 'multi_catches_jsp.jsp' will show you how to use multiple catch blocks to handle
JSP WITH MULTIPLE FORMS
in single jsp page. Most of the times people need to use multiple forms on a single page. For example on one web page you may add forms for login, search...;that we have made on a single page. Here you will see how this program works
retrieve multiple valuesfrom a single field
retrieve multiple valuesfrom a single field  hi i am doing...,s.perumbudur,poonamalle in a single record. i want to take the values from the stages field... value and s.perumbudur as one value in html. how to do
retrieve multiple valuesfrom a single field
retrieve multiple valuesfrom a single field  hi i am doing...,s.perumbudur,poonamalle in a single record. i want to take the values from the stages field... value and s.perumbudur as one value in html. how to do
retrieve multiple valuesfrom a single field
retrieve multiple valuesfrom a single field  hi i am doing...,s.perumbudur,poonamalle in a single record. i want to take the values from the stages field... value and s.perumbudur as one value in html. how to do
retrieve multiple valuesfrom a single field
retrieve multiple valuesfrom a single field  hi i am doing...,s.perumbudur,poonamalle in a single record. i want to take the values from the stages field... value and s.perumbudur as one value in html. how to do
retrieve multiple valuesfrom a single field
retrieve multiple valuesfrom a single field  hi i am doing...,s.perumbudur,poonamalle in a single record. i want to take the values from the stages field... value and s.perumbudur as one value in html. how to do
retrieve multiple valuesfrom a single field
retrieve multiple valuesfrom a single field  hi i am doing...,s.perumbudur,poonamalle in a single record. i want to take the values from the stages field... value and s.perumbudur as one value in html. how to do
How to insert multiple drop down list data in single column in sql database using servlet
How to insert multiple drop down list data in single column in sql database using servlet  i want to insert date of birth of user by using separate drop down list box for year,month and day into dateofbirth column in sql server
Create multiple pie chart in single frame using JFreeChart
you how to create a multiple pie charts in a single frame in jsp page using... Create multiple pie chart in single frame using JFreeChart.../Q", data);  final JFreeChart chart = 
executing multiple sql statements on the single button click...
executing multiple sql statements on the single button click...  how can i frame a code on the click of a button to insert data into a table as well as to retrieve records from the same table in another form
executing multiple sql statements on the single button click...
executing multiple sql statements on the single button click...  how can i frame a code on the click of a button to insert data into a table as well as to retrieve records from the same table in another form
how to display image and text in single jsp page from the mysql database
how to display image and text in single jsp page from the mysql database  hello please help me to display the image and text in single jsp page from mysql database if have any reference code please send me Thanks in advance
help me plz:-Merge multiple jasper files into Single one
help me plz:-Merge multiple jasper files into Single one  how to Merge multiple jasper files into Single one word doc
how to insert multiple columns of a single row into my sql database using jsp
how to insert multiple columns of a single row into my sql database using jsp  hi sir, how to insert multiple columns of a single row into my sql database using jsp. when i click ADD ROW,rows are added.when i click submit
java multiple users with single connection - JSP-Servlet
java multiple users with single connection  hi, my problem... it for multiple users who uses a single connection to the database simultaneously... of the above websites uses a single connection with multiple users. n
Multiple submit nuttons in single xhtml form - Java Server Faces Questions
Multiple submit nuttons in single xhtml form  Hi, I am facing problem in my JSF application, where in single page , we have two submit buttons. If any one of the button is clicked , then entire form is submitted. How to avoid
how to add web cam in web page
how to add web cam in web page  how do i embed my webcam in web page. code for embedding web cam in web page
how to create web page on jsp?
how to create web page on jsp?  how to create web page on jsp
Multiple submit buttons in single xhtml form - Java Server Faces Questions
Multiple submit buttons in single xhtml form  Hi all, Here I am attaching the source of the page , which containig two submit buttons. Somebody suggested to keep eaxh button in different form. I am new to JSF, can anyone split
How to change functionlatiy in web page
How to change functionlatiy in web page  i need to change functionality of my web page..i came to know that by using collections it is possible..but i dont know how to use it...is any other way to change functionality of my web
single selection of chechbox among multiple selection when in a loop.
single selection of chechbox among multiple selection when in a loop. ... that when in a loop i trying to choose single checkbox among multiple checkboxes but here am getting multiple selection(previous selected item also coming again
reading multiple files from a directory and writing them into a single file
reading multiple files from a directory and writing them into a single file   i have done the following code but the every time i write to the single... this: /*this program reads multiple files * from a single directory. */ package elite.tech.com
How to insert a single page PDF file into another multipage PDF file using iText? - Java Beginners
How to insert a single page PDF file into another multipage PDF file using.... PDF-B.pdf is a single page PDF file. I want to insert PDF-B into PDF-A only after every odd page. Any idea? Thanks
Multiple values for a single parameter
Multiple values for a single parameter   ... multiples values for a single parameter like in checkboxes. We are going to make one... the array use the for loop. The output will be displayed to you
May I know how to create a web page?
May I know how to create a web page?  can u suggest me how to start
Multiple Data Series in Chart in Flex4
Multiple Data Series in Chart in Flex4: In This example you can see how we can use multiple data series in a single chart. Every chart has a its own data...="Multiple Chart Series Example" width="659" height
How to print contents of a web page in jsp?
How to print contents of a web page in jsp?  I have generated a pay slip using jsp.How do I print the contents of the slip
how i open my web page
how i open my web page   how i open my web page on different broadband machine if i don't have any domain name... i m using a broadband .........i... localmachine/localhost:8080/app/app.htm so tell me step how i open my page
how to divide a web page into some frames.....
how to divide a web page into some frames.....  how to divide 1 web page into some parts. i know it using frames in html,bt how can we do it in jsp... page,bt m nt knowing how to divide that into frames in jsp.  Please go
how to remove the column from a java web page
how to remove the column from a java web page  i have a web page with account#, qtr, year if i want to remove the year column which is a drop down list from my jsp what should i do and what is the process please give a brief view
how to divide 1 web page into some parts...
how to divide 1 web page into some parts...  how to divide 1 web page into some parts...i know it using frames in html,bt how can we do it in jsp... home page,bt m nt knowing how to divide that into frames in jsp.   <
how to divide 1 web page into some parts...
how to divide 1 web page into some parts...  how to divide 1 web page into some parts...i know it using frames in html,bt how can we do it in jsp... home page,bt m nt knowing how to divide that into frames in jsp.  <
WEB PAGE
WEB PAGE  How To Create A Simple web Page Of a gmail using applet
using insert and delete in a single page in jsp
using insert and delete in a single page in jsp  I am using... in a single jsp page but insert function doesn't works only delete function works even... Insert and Delete in single page 1)application.jsp: <%@ page import="java.sql.
web page
web page  1.Create a web page with the following using HTML i) To embed an image map in a web page ii) To fix the hot spots iii) Show all the related information when the hot spots are clicked
Web Page
Web Page    Use any programming language or package to create... be prompted to register the username and password, and then allowed to use the username and the password to access the system (Main Menu for this Project). Use same
how to open a web page using proxy in java and handling button event in that web page..?
how to open a web page using proxy in java and handling button event in that web page..?  Sir, what i need is a code which uses proxy address and opens a web page i.e for example and then clicks a "yes" button in that page
How to carry multiple values from a Servlet to a JSP?
How to carry multiple values from a Servlet to a JSP?  By using the below code I am able to carry the username to a JSP (single value). ----response.sendRedirect("index.jsp?uname="+username);---- But I want multiple values
How to align the select tags in a single column.
How to align the select tags in a single column.  I am developing a JSP page with struts tags. In the JSP page I have a form where the candidate.... Can any one please help! I have tried to use table tag to align them but still

Ads