Posts

Showing posts with the label jsp

How to create DataGrid or GridView in JSP - Servlet

Image
Hi there, today I will like to share my knowledge on creating basic Datagrid in JSP. This is my solution but not a permanent solution in all other cases. Maybe you can enhance this code to achieve your own objective. In this tutorial, I will use basic servlet and JSP. Note: In this tutorial, I will use this library:- MySQL JDBC Driver JSTL 1.1 the project will run on source JDK 7 This is the database table DROP TABLE IF EXISTS `blogtest`.`usersprofile`; CREATE TABLE  `blogtest`.`usersprofile` (   `userid` varchar(30) NOT NULL,   `firstName` varchar(45) NOT NULL,   `lastName` varchar(45) NOT NULL,   `emailAddress` varchar(45) NOT NULL,   PRIMARY KEY (`userid`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; INSERT INTO `usersprofile` VALUES ('Ahmad','Ahmad','Ahmad','Ahmad@gmail.com'), ('Ahmad1','Ahmad1','Ahmad1','Ahmad1@gmail.com'), ('Ahmad10','Ahmad10','Ahmad10','Ahmad10@gmail.com'), ('Ahmad11&#

Arranging DIVs Horizontally

Image
Working with DIV tag is always problem and hard work thats why many web developers avoid creating their websites in DIV tag, in this tutorial, I will show you how to arrange DIVs in horizontal order with CSS. The HTML Code This is the html code for 4 divs div.container, div.left, div.middle and div.right. Note: Below the div.right there is another div with height:0; and width:100% and clear:both, the job of this div is to make sure the floating divs not going outside the container, try on your own to remove the div.clear to see what will happen on those floating div.    <div class="container">    <div class="left">Left</div>    <div class="middle">Middle</div>    <div class="right">Right</div>    <div class="clear"></div>    </div> The CSS Code .container{ width:600px; padding:0; border:5px solid #ddd; margin:0 auto; } .left{ float:left; width:150px; height:300px; te

Google Map API Zoom The Marker Example

Image
Google Map API Marker is a powerful API to use for web page to mark on the map for example the location of your business office. This tutorial can use in all framework as long as the framework use html language to render the content to client side. You can refer here for more information of Google Map API Let see the example in asp.net framework. The Javascript to call map and marker var map; function initializeGMap() {            var Centre = new google.maps.LatLng(3.15681, 101.714696);             var mapOptions = { zoom: 12, center: Centre, mapTypeId: google.maps.MapTypeId.ROADMAP };             map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);             var KLCC = new google.maps.LatLng(3.15681, 101.714696);             var marker = new google.maps.Marker({ position: KLCC, map: map, title: 'Kuala Lumpur City Center' });          }         google.maps.event.addDomListener(window, 'load', initializeGMap); The Zoom Marker Script fu

Disable Back Browser Button in web Page

Image
This example will show how to disable Back button in your browser. To achieve this objective, the javascript will be use to redirect back to the current page if the user click on the browser back button and give message to user. So let see the example. I'll set the script at HEAD element and use onpageshow and  onload event in the body element. The Javascript put in Head element <script type="text/javascript">         window.history.forward();         function noBack() { window.history.forward(); document.getElementById("Message").innerHTML = "You cannot Go Back"; }     </script> The Html/Aspx/Jsp page : : Head element : <body onpageshow="if (event.persisted) noBack();" onload="noBack();" > : : body content  <div id="Message" style="color:red;">  </div> : : </body> </html> The Output If the user click on the browser back button, the script will automatically redirect to

Java - Get Visitor/Client ip address : JSP : Servlet

The previous post show how to get Visitor or client ip address in C# / ASP.NET . This post will show how to get ip address of client / visitor from jsp / servlet application. In order to make this method work, you need to test this method on the server and you are accessing the server from your computer. Otherwise you will get your local ipaddress or ::1 value. The getClientIpAddr Method      public static String getClientIpAddr(HttpServletRequest request) {          String ip = request.getHeader("X-FORWARDED-FOR");          if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {              ip = request.getHeader("Proxy-Client-IP");          }          if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {              ip = request.getHeader("WL-Proxy-Client-IP");          }          if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {              ip = request.getHeader(&

How to create zip file to download in JSP- Servlet

Image
Hye, my previous post show that how to download zip file in ASP.NET ,. In this tutorial i will show the same thing, but in Jsp-Servlet. Note : In this tutorial i will use this library :- JSTL 1.1  The JSP File  <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html>     <head>         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">         <title>Download File As ZIP File</title>     </head>     <body>        <h1>Download File As ZIP File</h1>         ${DownloadMessage}         <br/>         <form action="<c:url value="/downloadFileServletZip" />" method="post" >             Default Path is server to download is D:\JAVA\dist\Output\             <input type="submit" name="bDownload"

Multiple button in one form JSP - Servlet

Image
Hi there, today I will show one simple tutorial to show which button is clicked in one form. The idea after I read this post on the forum how to find which button is clicked Note : In this tutorial i will use this library :- JSTL 1.1 Here is the example The JSP File <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html>     <head>         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">         <title>Multiple Buttom In Form</title>     </head>     <body>         <h1>Multiple Button In Form</h1>         ${message}         <br/>         <form action="<c:url value="/servletMultipleButton" />" method="POST">            <input type="submit" name="BModify" value="Modify" >&l