- Java Server Pages (JSP) : Advantages over Servlets and other technologies
- How to create simple Hello World Servlet application in Java ?
- What is a Web Application in Java programming language?
- A Simple HTML and JSP Email Subscription List Application
- How to get real path for a file in JSP and Servlet ?.
- How to use various types of JSP tags in a JSP page ?
- How to set and get an attribute to/from request object in JSP and Servlets ?
- How to redirect responses to a different JSP or Servlets ?.
- How to add and retrieve Sessions in JSP and Servlets using Session Management API ?
- How to destroy a session in JSP and Servlets using Session Management API ?
- How to expire and destroy Cookies in JSP and Servlets ?
- A simple application demonstrating Request, Session, Context differences and usages in JSP and Servlets
- How to check whether which Web-Browser have been used to run JSP and Servlets ?.
- How to add and retrieve Sessions in JSP and Servlets using Session Management API ?
- How to destroy a session in JSP and Servlets using Session Management API ?
- How to perform create sql query in JSP and Servlets using JDBC ?
- How to perform insert sql query in JSP and Servlets using JDBC ?
- How to perform update sql query in JSP and Servlets using JDBC ?
- How to create a Filter that adds url and time of request to a database in JSP and Servlets ?.
- How to perform delete sql query in JSP and Servlets using JDBC ?
- How to create error page in a JSP and Servlet to handle exceptions ?
- How to use filters in JSP and Servlets for logging information in ServletContext logs ?
- How to include JSP page dynamically into another JSP page?
- How to display HTTP Request Headers through a Servlet ?.
- How to display Request url Information through a Servlet ?
- How to display request parameters in a JSP coming in a request ?.
- How to use model / Java / Pojo classes with JSP and Servlets ?.
- How to forward a request to a JSP using RequestDispatcher ?.
- How to do Session Management in JSP and Servlets using its methods and API ?.
- How to forward a request from one Jsp to another Jsp ?.
- How to include one JSP into another JSP ?.
- How to use Jsp action elements useBean, setProperty and getProperty to add, set and get property of a bean in a JSP page ?.
- How to decorate form in a JSP using fieldset and legend tag ?.
- How to write a Servlet code to download a Jar or file from the Server at a specified location ?.
- How to use Servlets Initialization Parameters through ServletConfig object in Java EE Application ?.
- How to use Context Parameters in Servlets through ServletContext object in Java EE Application ?.
- "Online Tweeter Enterprise Application" : Creating a JSP page in NetBeans Web module - Part 6
- "Online Tweeter Enterprise Application" : Creating a Servlet named DisplayTweets in NetBeans Web module - Part 9
- How to use Arithmetic Operations in Expression Language ( el ) in a simple jsp page ?.
- "Online Tweeter Enterprise Application" : Creating a Servlet named TweetsSubmit in NetBeans Web module - Part 8
- How to use param implicit object in a JSP page ?.
Free Data Structures and Algorithms Course
Showing posts with label Java Server Pages and Servlets. Show all posts
Showing posts with label Java Server Pages and Servlets. Show all posts
JSP and Servlet Programming
How to use param implicit object in a JSP page ?.
A simple web application demonstrating how to use param implicit object in a jsp.
1. Create a simple jsp page as "param.jsp".
2. Create a simple jsp page by name "display.jsp"
display.jsp page use implicit object called as param to retrieve the form values coming as a post request.
Run param.jsp and enter username and click submit:
On clicking submit the form values passed as username to display.jsp which uses param implicit object to retrieve the value of username as shown below in the fig.
1. Create a simple jsp page as "param.jsp".
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <form method="post" action="display.jsp"> <tr> <td>Enter Your Name:</td> <td><input name="username" type="text"></td> </tr> <tr> <td colspan="2"><input type="submit" value="Submit"></td> </tr> </form> </body> </html>
2. Create a simple jsp page by name "display.jsp"
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <h2>Name entered: ${param.username}</h2> </body> </html>
display.jsp page use implicit object called as param to retrieve the form values coming as a post request.
Run param.jsp and enter username and click submit:
On clicking submit the form values passed as username to display.jsp which uses param implicit object to retrieve the value of username as shown below in the fig.
"Online Tweeter Enterprise Application" : Creating a Servlet named DisplayTweets in NetBeans Web module - Part 9
Lets continue building "Online Tweeter Enterprise Application" in NetBeans. In this section of tutorial, you will create a Servlets in Web module by name "DisplayTweets.java". A Servlet is a server side program which executes at the server producing dynamic content for the web applications.
Step 1: Open "Tweeter-war" project and right click Source Packages and then select New and than Other as shown in fig below:
Step 2: On clicking Other a dialog box appears by name New File. In the Categories: list select Web and in the File Types: select Servlet as shown in fig below.
Step 1: Open "Tweeter-war" project and right click Source Packages and then select New and than Other as shown in fig below:
Step 2: On clicking Other a dialog box appears by name New File. In the Categories: list select Web and in the File Types: select Servlet as shown in fig below.
Step 3: Click

.
New Servlet dialog box gets open. It prompts us to enter Class Name: , Project: , Location: , Package: and Created File: etc. Enter the values as shown in the fig below.

Step 4: Click

.
yet another New Servlet dialog box gets open. It prompts us to enter values related to Servlet deployment. Do not check "Add information to deployment descriptor (web.xml)". Just enter values as shown in figure below.
and than just click
A new servlet gets created in the source packages by name DisplayTweets.java. It has code which is generated by NetBeans. Just add or remove code given below.
package com.hubberspot.servlets; import com.hubberspot.ejb.ActiveFollowersOnline; import com.hubberspot.ejb.Tweet; import com.hubberspot.ejb.TweetsFinder; import java.io.IOException; import java.io.PrintWriter; import java.util.Iterator; import java.util.List; import javax.ejb.EJB; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; @WebServlet(name = "DisplayTweets", urlPatterns = {"/DisplayTweets"}) public class DisplayTweets extends HttpServlet { @EJB private TweetsFinder tweetsFinder; @EJB private ActiveFollowersOnline activeFollowersOnline; protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); request.getSession(true); PrintWriter out = response.getWriter(); try { out.println(""); out.println(""); out.println(""); out.println("Latest Tweets "); out.println(""); out.println(""); out.println("
"); out.println("Latest Tweets"); out.println(" | "); out.println(""); out.println("Add new tweets"); out.println(" | "); out.println(activeFollowersOnline.getFollowersOnline() + " follower(s) reading tweets."); out.println(" | "); out.println("
"); List tweets = tweetsFinder.findAllTweets(); for (Iterator it = tweets.iterator(); it.hasNext();) { Tweet tweet = (Tweet) it.next(); out.println("
"); out.println("User: " + tweet.getUsername() + ""); out.println(" | "); out.println("
"); out.println("Tweeted: " + tweet.getTweet() + ""); out.println(" | "); out.println("
"); } out.println(""); out.println(""); } finally { out.close(); } } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } @Override public String getServletInfo() { return "Short description"; } }
In the next section of this blog (part 10) you will learn how to build and run the application in NetBeans.
How to use Arithmetic Operations in Expression Language ( el ) in a simple jsp page ?.
A simple jsp to demonstrate how to use Arithmetic Operations in Expression Language ( el ).
Output of the Jsp Page :
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body style="background-color: lightblue"> <h2>Arithmetic Operations with EL !</h2> <table border="2"> <thead> <tr> <th>Operation</th> <th>EL Expression</th> <th>Result</th> </tr> </thead> <tbody> <tr> <td>Digit</td> <td>\${8}</td> <td>${8}</td> </tr> <tr> <td>Addition</td> <td>\${4+4}</td> <td>${4+4}</td> </tr> <tr> <td>Addition</td> <td>\${5.5+4.5}</td> <td>${5.5+4.5}</td> </tr> <tr> <td>Subtraction</td> <td>\${15-5}</td> <td>${15-5}</td> </tr> <tr> <td>Division</td> <td>\${20/4}</td> <td>${20/4}</td> </tr> <tr> <td>Multiplication</td> <td>\${2*4}</td> <td>${2*4}</td> </tr> <tr> <td>Modulus</td> <td>\${21%4}</td> <td>${21%4}</td> </tr> </tbody> </table> </body> </html>
Output of the Jsp Page :
"Online Tweeter Enterprise Application" : Creating a Servlet named TweetsSubmit in NetBeans Web module - Part 8
Lets continue building "Online Tweeter Enterprise Application" in NetBeans. In this section of tutorial, you will create a Servlets in Web module by name "TweetsSubmit.java". A Servlet is a server side program which executes at the server producing dynamic content for the web applications.
Step 1: Open "Tweeter-war" project and right click Source Packages and then select New and than Other as shown in fig below:
Step 2: On clicking Other a dialog box appears by name New File. In the Categories: list select Web and in the File Types: select Servlet as shown in fig below.
Step 1: Open "Tweeter-war" project and right click Source Packages and then select New and than Other as shown in fig below:
Step 2: On clicking Other a dialog box appears by name New File. In the Categories: list select Web and in the File Types: select Servlet as shown in fig below.
Step 3: Click

.
New Servlet dialog box gets open. It prompts us to enter Class Name: , Project: , Location: , Package: and Created File: etc. Enter the values as shown in the fig below.
Step 4: Click

.
yet New Servlet dialog box gets open. It prompts us to enter values related to Servlet deployment. Do not check "Add information to deployment descriptor (web.xml)". Just enter values as shown in figure below.
and than just click
A new servlet gets created in the source packages by name TweetsSubmit.java. It has code which is generated by NetBeans. Just add or remove code given below.
package com.hubberspot.servlets; import com.hubberspot.ejb.Tweet; import java.io.IOException; import java.io.PrintWriter; import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.Resource; import javax.jms.*; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet(name = "TweetsSubmit", urlPatterns = {"/TweetsSubmit"}) public class TweetsSubmit extends HttpServlet { @Resource(mappedName = "jms/tweetsFactory") private ConnectionFactory connectionFactory; @Resource(mappedName = "jms/tweets") private Queue queue; protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); String username = request.getParameter("txtUsername"); String tweet = request.getParameter("txtTweet"); if (username != null && tweet != null) { try { Connection connection = connectionFactory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer messageProducer = session.createProducer(queue); ObjectMessage objectMessage = session.createObjectMessage(); Tweet newTweet = new Tweet(); newTweet.setUsername(username); newTweet.setTweet(tweet); objectMessage.setObject(newTweet); messageProducer.send(objectMessage); connection.close(); response.sendRedirect("DisplayTweets"); } catch (JMSException ex) { Logger.getLogger(TweetsSubmit.class.getName()).log(Level.SEVERE, null, ex); } } } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } @Override public String getServletInfo() { return "Short description"; } }
In the next section of this blog (part 9) you will learn how to create a yet another Servlet in NetBeans by name DisplayTweets, for this application in the Web module.
"Online Tweeter Enterprise Application" : Creating a JSP page in NetBeans Web module - Part 6
Lets continue building "Online Tweeter Enterprise Application" in NetBeans. In this section of tutorial, you will create a Java Server Pages (JSP) by name "tweets.jsp". A JSP page is like a User Interface for Web Application. Its like a dynamic web page having html with java embedded into it.
Step 1: Open "Tweeter-war" project and right click Web Pages and then select New and than Other as shown in fig below.
Step 2: On clicking Other a dialog box appears by name New File. In the Categories: list select Web and in the File Types: select JSP as shown in fig below.
Step 3: Click

.
New JSP dialog box gets open. It prompts us to enter values for the File Name: , Project: , Location: , Folder: , Created File: and Options: .Enter the required values as per fig shown below.
Step 4: Click
A new jsp page gets created by the name tweets.jsp in the "Tweeter-war" module.Kindly add or remove additional code provided below.
Output of the jsp on browser window :
tweets.jsp is a simple web page having few html components which prompts user to enter UserName , Tweet he/she wants to publish and than click on Submit button.
In the next section of this blog (part 7) you will learn how to create a Singleton Session Bean in NetBeans for this application in the Web module.
Step 1: Open "Tweeter-war" project and right click Web Pages and then select New and than Other as shown in fig below.
Step 2: On clicking Other a dialog box appears by name New File. In the Categories: list select Web and in the File Types: select JSP as shown in fig below.
Step 3: Click

.
New JSP dialog box gets open. It prompts us to enter values for the File Name: , Project: , Location: , Folder: , Created File: and Options: .Enter the required values as per fig shown below.
Step 4: Click
A new jsp page gets created by the name tweets.jsp in the "Tweeter-war" module.Kindly add or remove additional code provided below.
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Tweeter</title> </head> <body> <table border="0" bgcolor="aquagreen" cellpadding="0" cellspacing="0" width="60%"> <tr> <td> <table border="0" align="center" cellpadding="0" cellspacing="0" width="100%"> <tr> <td valign="middle" align="center" style="padding-right:0px; padding-left:0px; padding-bottom:0px; font:24px/30px Georgia; width:228px; color:#FFFFFF; padding-top:0px; height:37px;"> What's happening ?. !!! </td> </tr> </table> </td> </tr> <tr align="left" valign="top"> <td height="20"> <hr /> </td> </tr> <tr> <td> <form name="tweetsForm" action="TweetsSubmit" method="post"> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td align="right" valign="top"> UserName: </td> <td> <input type="text" name="txtUsername" size="50" maxlength="75"/> </td> </tr> <tr> <td> <br/> </td> </tr> <tr> <td align="right" valign="top"> Your Tweet: </td> <td> <textarea name="txtTweet" cols="38" rows="6"></textarea> </td> </tr> <tr align="left"> <td height="20"> <hr /> </td> <td height="20"> <hr /> </td> </tr> <tr> <td colspan="2" align="left"> <input type="submit" value="Tweet" /> </td> </tr> </table> </form> </td> </tr> </table> </body> </html>
Output of the jsp on browser window :
tweets.jsp is a simple web page having few html components which prompts user to enter UserName , Tweet he/she wants to publish and than click on Submit button.
In the next section of this blog (part 7) you will learn how to create a Singleton Session Bean in NetBeans for this application in the Web module.
How to use Context Parameters in Servlets through ServletContext object in Java EE Application ?.
A simple Servlet code to demonstrate how to use Context Parameters through ServletContext object in Java EE Application.
1. Implementing Context Parameters in web.xml as name/value pair.
2. Servlet Code using Context Parameters implemented above in web.xml
Output of the program :
1. Implementing Context Parameters in web.xml as name/value pair.
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <context-param> <param-name>Username</param-name> <param-value>Jontymagicman</param-value> </context-param> <context-param> <param-name>Website</param-name> <param-value>Hubberspot</param-value> </context-param> <context-param> <param-name>Email</param-name> <param-value>jonty@hubberspot.com</param-value> </context-param> <servlet> <servlet-name>ContextParameterDemo</servlet-name> <servlet-class>com.hubberspot.context.parameter.ContextParameterDemo</servlet-class> </servlet> <servlet-mapping> <servlet-name>ContextParameterDemo</servlet-name> <url-pattern>/ContextParameterDemo</url-pattern> </servlet-mapping> <session-config> <session-timeout> 30 </session-timeout> </session-config> </web-app> |
2. Servlet Code using Context Parameters implemented above in web.xml
package com.hubberspot.context.parameter; import java.io.IOException; import java.io.PrintWriter; import java.util.Enumeration; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class ContextParameterDemo extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); try { out.println(""); out.println(""); out.println("Context Parameter Demo "); out.println(""); out.println(""); out.println("Context-Parameters Demo (ServletContext)
"); ServletContext context = this.getServletContext(); Enumeration params = context.getInitParameterNames(); int counter = 1; while(params.hasMoreElements()){ String paramName = (String) params.nextElement(); out.print(counter + ". param name = " + paramName + ""); out.println(" "+ counter + ". param value = " + context.getInitParameter(paramName) + " "); counter++; } out.println("Username is : " + context.getInitParameter("Username") + "" ); out.println("Email is : " + context.getInitParameter("Email") + "" ); out.println("Website is : " + context.getInitParameter("Website") + "" ); out.println(""); out.println(""); } finally { out.close(); } } }
Output of the program :
How to use Servlets Initialization Parameters through ServletConfig object in Java EE Application ?.
A simple Servlet code to demonstrate how to use Servlets Initialization Parameters through ServletConfig object in Java EE Application.
1. Implementing Initialization Parameters in web.xml as name/value pair.
2. Servlet Code using Initialization Parameters implemented above in web.xml
Output of the program :
1. Implementing Initialization Parameters in web.xml as name/value pair.
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <servlet> <servlet-name>InitParameterDemo</servlet-name> <servlet-class>com.hubberspot.init.parameter.InitParameterDemo</servlet-class> <init-param> <param-name>Username</param-name> <param-value>Jontymagicman</param-value> </init-param> <init-param> <param-name>Website</param-name> <param-value>Hubberspot</param-value> </init-param> <init-param> <param-name>Email</param-name> <param-value>jonty@hubberspot.com</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>InitParameterDemo</servlet-name> <url-pattern>/InitParameterDemo</url-pattern> </servlet-mapping> <session-config> <session-timeout> 30 </session-timeout> </session-config> </web-app> |
2. Servlet Code using Initialization Parameters implemented above in web.xml
package com.hubberspot.init.parameter; import java.io.IOException; import java.io.PrintWriter; import java.util.Enumeration; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class InitParameterDemo extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); try { out.println(""); out.println(""); out.println("Init Parameter Demo "); out.println(""); out.println(""); out.println("Init-Parameters Demo (ServletConfig)
"); ServletConfig config = this.getServletConfig(); Enumeration params = config.getInitParameterNames(); int counter = 1; while(params.hasMoreElements()){ String paramName = (String) params.nextElement(); out.print(counter + ". param name = " + paramName + ""); out.println(" "+ counter + ". param value = " + config.getInitParameter(paramName) + " "); counter++; } out.println("Username is : " + config.getInitParameter("Username") + "" ); out.println("Email is : " + config.getInitParameter("Email") + "" ); out.println("Website is : " + config.getInitParameter("Website") + "" ); out.println(""); out.println(""); } finally { out.close(); } } }
Output of the program :
How to write a Servlet code to download a Jar or file from the Server at a specified location ?.
A simple application demonstrating how to write a Servlet code to download a Jar or file from the Server at a specified location.
1. A simple html file for sending a get request to server for the Jar/file.
2. Servlet code for downloading a Jar/file to a specified location on client's machine.
(Output) Running Download.html :
(Output) On clicking the "Download Jar" link we get the download file pop-up (Save as to specified location)
1. A simple html file for sending a get request to server for the Jar/file.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Download Jar</title> </head> <body> <h2>Download Page !!!!</h2> <a href="DownloadJarServlet">Download Jar</a> </body> </html>
2. Servlet code for downloading a Jar/file to a specified location on client's machine.
package com.download.jar; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet("/DownloadJarServlet") public class DownloadJar extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 1. Helping the browser to understand that it is // a jar file not an html content. // Inorder to pass this information in response // we set the content type as "application/jar" // by calling setContentType() method in response object response.setContentType("application/jar"); // 2. Getting the ServletContext object by calling // getServletContext() method from the current servlet object ServletContext ctx = getServletContext(); // 3. From ServletContext object we are calling getResourceAsStream() // which returns the resource located at the named path as an InputStream object. // The data in the InputStream can be of any type or length. // This method returns null if no resource exists at the specified path. // here we are passing the jar name present in the server at the relative path InputStream is = ctx.getResourceAsStream("/mail.jar"); int read = 0; byte[] noOfBytes = new byte[1024]; // 4. Getting the outputstream from the response object to write // contents of jar to browser OutputStream os = response.getOutputStream(); // 5. Reading the contents of jar in bytes using the inputstream created above // and writing it to the browser through outputstream created above. while((read = is.read(noOfBytes)) != -1 ){ os.write(noOfBytes, 0 , read); } os.flush(); os.close(); } }
(Output) Running Download.html :
(Output) On clicking the "Download Jar" link we get the download file pop-up (Save as to specified location)
How to decorate form in a JSP using fieldset and legend tag ?.
A simple JSP decoration application using Fieldset and legend tag
Output of the program :
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>User Details</title> </head> <body> <table bgcolor="pink" border="0" cellpadding="0" cellspacing="0" align="center" width="760"> <tr> <td> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td valign="top" align="left" style="padding-left: 0px; padding-right: 0px; padding-top: 0px; padding-bottom: 0px; font: 24px/30px Georgia; width: 228px; color: #768e4e; height: 37px"> User Details</td> </tr> </table> </td> </tr> <tr> <td> <form action="" method="post"> <table border="0" cellpadding="0" cellspacing="2"> <tr> <td align="right"> <fieldset> <legend style="font-size: 18px; font-weight: bold; color: maroon; font-family: Georgia, serif;"> UserDetails </legend> <table border="0" cellpadding="3" cellspacing="0"> <tr> <td align="right"><font style="font-size: 15px; font-family: Arial, Times, serif; font-weight: bold">First Name:</font></td> <td><input name="txtFirstName" maxlength="25" size="50"> </td> </tr> <tr> <td align="right"><font style="font-size: 15px; font-family: Arial, Times, serif; font-weight: bold">Last Name:</font></td> <td><input name="txtLastName" maxlength="25" size="50"> </td> </tr> <tr> <td align="right"><font style="font-size: 15px; font-family: Arial, Times, serif; font-weight: bold">Password:</font> </td> <td><input type="password" name="txtLastName" maxlength="25" size="50"></td> </tr> </table> </fieldset> </td> </tr> <tr> <td align="right"> <fieldset> <legend style="font-size: 18px; font-weight: bold; color: maroon; font-family: Georgia, serif;"> ContactDetails </legend> <table border="0" cellpadding="3" cellspacing="0"> <tr> <td align="right"><font style="font-size: 15px; font-family: Arial, Times, serif; font-weight: bold">Email Address:</font></td> <td><input name="txtEmailAddress" maxlength="48" size="50"></td> </tr> <tr> <td align="right"><font style="font-size: 15px; font-family: Arial, Times, serif; font-weight: bold">Mobile Number:</font></td> <td><input name="txtMobileNumber" maxlength="25" size="50"></td> </tr> </table> </fieldset> </td> </tr> <tr> <td align="right"><br /> <input type="submit" name="btnSubmit" value="Submit" /></td> </tr> </table> </form> </td> </tr> </table> </body> </html>
Output of the program :
How to use Jsp action elements useBean, setProperty and getProperty to add, set and get property of a bean in a JSP page ?.
A simple Web-Application showing how to use action jsp action elements useBean, setProperty and getProperty to add, set and get property of a bean in a JSP page
Create a simple JavaBean by name User.java
Create style.css file
Create user.jsp file
Create done.jsp file
After running JSP's on browser :
On Updating the User details :
Create a simple JavaBean by name User.java
package com.hubberspot.bean; public class User { private String firstName; private String lastName; private String email; private String password; public User() { } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
Create style.css file
body { font-family: Verdana, Geneva, Arial, helvetica, sans-serif; background-color: #FDF4DF; font-size: 14px; color: #333333; } td { font-family: Verdana, Geneva, Arial, helvetica, sans-serif; font-size: 14px; } .small { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; }
Create user.jsp file
|
Create done.jsp file
|
After running JSP's on browser :
On Updating the User details :
Subscribe to:
Posts (Atom)