J2EE

JSP Servlet with AJAX Example

J2EE
JSP Servlet with AJAX Example Ajax is a great feature implemented almost in all the websites in some way. It gives really a very good user interface, since things are loading/populating without refresh. It is commonly used in username availability checking, register/login page db level/business level validations etc. We are going to use Ajax with JSP and servlet to calculate the EMI payable amount by giving amount, month and interest rate in single screen(without refreshing). Requirements: 1. Include jQuery library (since we used $.get for ajax response) 2. Include Bootstrap libraries (for responsiveness) Including jQuery and Bootstrap libraries in header section: [html] <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" /> <script src="js/jquery-...

EMI Calculator using JSP, Servlet and Bootstrap

J2EE, Java
EMI Calculator using JSP, Servlet and Bootstrap: Designing a responsive website reduces the startups to invest separately on android and ios apps. Here we are writting a very simple web application for emi calculator using JSP, Servlet and bootstrap. We used bootstrap in this to integrate responsiveness with JSP pages.     Requirement: Download bootstrap CSS and JS files from here. Include the bootstrap css and JS files in the head section, [html] <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>EMI Calculator</title> <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> <script src="bootstrap/js/bootstrap.min.js" type="text/javascript"> </script> <...

Pass values from one jsp to another jsp file

J2EE
Pass values from one jsp to another jsp file: Form values from one jsp can be sent to another jsp file with action parameter in form and getParameter method in the second jsp file. Things to remember: Mention the jsp2.jsp file in the form action of jsp1.jsp file. In jsp2.jsp file use getParameter() method and pass the name of the form element inside to get the value whichever is passed from jsp1.jsp file.     jsp1.jsp file: [html] <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!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&g...

Installing Maven in eclipse

J2EE, Tools
Installing Maven in eclipse: Maven can be installed in eclipse by two ways, 1. Through eclipse marketplace [Help -> Eclipse Marketplace] Search M2E or Maven Integration for Eclipse    M2E - Maven Integration for Eclipse then install this package. 2. Install New Software [Help ->  Install New software] Enter the below URL and select all then click next and finish to install the maven in eclipse. http://download.eclipse.org/technology/m2e/releases   If you are using eclipse juno/helios/indigo you should install the maven in either of the above ways. Facing any issue in both of the above ways. Then better download the Eclipse Mars, which will have the ant, maven and many useful tools in the package itself. So that we do not want to install anything externally. How
JSON in Servlet with Ajax call

JSON in Servlet with Ajax call

J2EE
JSON in Servlet with Ajax call: JSON is a amazing alternate for XML to pass/transfer the informations. It is required to know how to handle JSON in servlet. In servlet it can be handled like this, [plain] request.setCharacterEncoding("utf8"); response.setContentType("application/json"); // json is the JSON object. response.getWriter().print(json); [/plain] But if you want to call your servlet through ajax, then we should handle the JSON response in JS also to display JSON in jsp page, else only object object will be printed in JSP page. Ajax JS changes to display JSON: [plain] // for json [if responseText is JSON ] $('#printJSON').text(JSON.stringify(responseText)); // for string [if responseText is String ] $('#printJSON').tex...

clicked value passing from one jsp to another jsp

J2EE
Create the first jsp named main.jsp and paste the below code,   [html] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <html> <head> <title>agn</title> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta name="GENERATOR" content="Rational Application Developer"> </head> <body> <!--<iframe src="http://www.w3schools.com"> <p>Your browser does not support iframes.</p> </iframe> --> <a href=&quo...

spring mvc hello world example step by step

J2EE
Spring hello world...!!! Step 1:  Create a dynamic web project named "JavadomainSpringMVC". Step 2: Download and add the below mentioned spring jar files to lib folder which is in WebContent/WEB-INF/lib. Required Spring jar files: 1. commons-logging-1.0.4 2. jstl-1.2 3. org.springframework.asm-3.1.0.RELEASE 4. org.springframework.beans-3.1.0.RELEASE 5. org.springframework.context-3.1.0.RELEASE 6. org.springframework.core-3.1.0.RELEASE 7. org.springframework.expression-3.1.0.RELEASE 8. org.springframework.web.servlet-3.1.0.RELEASE 9. org.springframework.web-3.1.0.RELEASE 10. spring-web-3.2.1.RELEASE Download all jar files Step 2: Create a package named "in.javadomain.spring.controller" under src. Step 3: Create a java class (here controller) named "B

Jelastic to host your java web application for free

J2EE
Is it ? Yes Now you can host your java website with database connection for free. Who all are providing java web application host for free ? Many sites providing us to host the free java web application, But rightnow I checked only http://jelastic.com/ Jelastic free java web application steps: 1. You have to create the free account in jelastic.com 2. Login with the created account and credentials. 3. After login you will be able to see the option called "Create Environment". Click and create the environment as like below, 4.  After creating the environment you will be able to see the "Deployment Manager". You have to upload your war files. 5. Once the war file uploaded you will be able to Deploy it. 6.  Then open the link (deployment) and you will b

Session Validation in Ajax

J2EE, Javascript
Session validation in servlet: Usually if it is a servlet we can simply check if(session != null ){ // Business code }else{ // Redirection code }   Session validation in ajax: If you call the servlet from ajax then the above steps won't work, since ajax gets everything as response, so the code which you have written in the else block (Redirection code) will also be sent as response, so expected redirection will not happen. So what can we do ? We have to send the response from servlet to ajax (eg: json ) for both the cases (session valid and session invalid). if(session !=null) { json.put("session_status",true) }else{ json.put("session_status",false) } out.println(json.toString()); we have to check the session_status in ajax whether it is true or false like ...

Passing clicked value from jsp to jsp/servlet

J2EE
Passing value from jsp to jsp/servlet: We can pass the value from jsp to servlet using, request.getParameter("text"); //servlet code to get the jsp value where text is the name of the input fields (text field). Passing clicked value from jsp to jsp/servlet: We have to pass the clicked value as get parameter in the href link like below, <a href="/Myservlet?input=javadomain"> MyServlet is the name of the servlet. Servlet code: request.getParameter("input"); So javadomain will be passed from jsp to servlet. In the below sample program javadomain (small letters) will be clicked, then the same value passed from jsp to servlet and there javadomain(small letters) are converted to JAVADOMAIN (UPPER CASE) then the new upper case values are passed from servlet to jsp. P...