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



Home Answers Viewqa JSP-Servlet how to use a single web page multiple functionaliteies

Have Programming Question? Ask it here!
 
 
 


ranireddy
how to use a single web page multiple functionaliteies
2 Answer(s)      2 years and 6 months ago
Posted in : JSP-Servlet


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...


Advertisement
View Answers

February 23, 2012 at 5:20 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:22 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
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
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
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
Use multiple catch statement in single jsp
Use multiple catch statement in single jsp       In java a single try can have multiple..._jsp.jsp' will show you how to use multiple catch blocks to handle multiple
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... on a single page. Here you will see how this program works. Suppose if you
multiple submits, single form.
multiple submits, single form.  is it possible to use multiple submit buttons in a single form?   Thank you
how to create web page on jsp?
how to create web page on jsp?  how to create web page on jsp
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
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 = 
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 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
How to use Jquery in jsp page
How to use Jquery in jsp page  Hello Sir, I am developing a web application in which i have to show database table values into Gridview in my jsp page. I have heard that jquery will be usefull for this work
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 use 'if' statement in jsp page?
How to use 'if' statement in jsp page?  ... how to use 'if' statement in jsp page. This statement is used to test...; in the tomcat-6.0.16/webapps and paste WEB-INF directory in same. use
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
How to use 'for' loop in jsp page?
How to use 'for' loop in jsp page?       This is detailed java code that shows how to use.... In this example, we have developed use_for_loop.jsp page which shows the use
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
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
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
how to use web services to access hardware units ?
how to use web services to access hardware units ?  Hi I am suresh raja i am doing a project on electronic meter i have to get meter reading with the help of web services and store it to database is it possible to do ! please
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
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
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
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 use an object properties in jsp page
How to use an object properties in jsp page  I have a arraylist of objects 'User' populated using struts 2 action class while loading that jsp page... of hardcoded value 'AMIT' I want to use value of User object. How can I do it? Please
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
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
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
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 use 'for' loop in jsp page?
How to use 'for' loop in jsp page?       This is detailed java code that shows how to use.... In this example, we have developed use_for_loop.jsp page which shows the use
How to use 'continue' keyword in jsp page ?
How to use 'continue' keyword in jsp page... that shows how to use 'continue' keyword in jsp page. The continue statement skips... have developed use_continue_statement.jsp page which shows the use of 'continue
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
How to use radio button in jsp page
How to use radio button in jsp page       This is detailed java code how to use radio button in jsp code and display a message in another jsp page according
How to create and use custom error page in jsp
How to create and use custom error page in jsp       This is detailed java code how to create and use custom error page in jsp and display an error message. Before run
 

 

 

DMCA.com