Skip to content

Instantly share code, notes, and snippets.

<html>
<head></head>
<body>
<h3>Training</h3>
<%
//the default..if there are no cookies
String favlang = "Java";
//get the cookies from the browser request
Cookie[] theCookies = request.getCookies();
@raunakhajela
raunakhajela / todo-demo.jsp
Created January 12, 2018 07:59
JSP: Sessions - Writing Data
<!--
isNew() : boolean - returns true if the session is new
getId() : String - returns the session id
invalidate() : void - invalidates this session and unbinds any object associated with it
setMaxInactiveInterval(long mills) : void - sets the idle time for a session to expire, the value is supplied in milliseconds
-->
<%@ page import="java.util.*" %>
<html>
<body>
@raunakhajela
raunakhajela / student-checkbox-form.html
Created January 11, 2018 07:42
JSP: Forms - Checkboxes
<html>
<body>
<form action="student-checkbox-response.jsp">
First name: <input type="text" name="fname" />
<br/><br/>
Last name: <input type="text" name="lname" />
<br/><br/>
<input type="checkbox" name="flang" value="java"/> Java
<input type="checkbox" name="flang" value="php"/> PHP
<input type="checkbox" name="flang" value="c"/> C
@raunakhajela
raunakhajela / student-radio-form.html
Created January 11, 2018 07:36
JSP: Forms - Radiobuttons
<html>
<body>
<form action="student-radio-response.jsp">
First name: <input type="text" name="fname" />
<br/><br/>
Last name: <input type="text" name="lname" />
<br/><br/>
<input type="radio" name="flang" value="java"/> Java
<input type="radio" name="flang" value="php"/> PHP
<input type="radio" name="flang" value="c"/> C
@raunakhajela
raunakhajela / student-dropdown-form.html
Created January 11, 2018 07:32
JSP: Forms - Dropdowns
<html>
<body>
<form action="student-dropdown-response.jsp">
First name: <input type="text" name="fname" />
<br/><br/>
Last name: <input type="text" name="lname" />
<br/><br/>
<select name="country">
<option>Brazil</option>
<option>France</option>
<html>
<body>
<form action="student-response.jsp">
First name: <input type="text" name="fname" />
<br/><br/>
Last name: <input type="text" name="lname" />
<br/><br/>
<input type="submit" value="Submit" />
</form>
</body>
@raunakhajela
raunakhajela / homepage.jsp
Created January 11, 2018 07:18
JSP: Including Files
<html>
<body>
<jsp:include page="my-header.html" />
<p>Power Women's Attract L Black Running Shoes - 5 UK/India (38 EU)(5396053)</p>
<p>Power Women's Attract L Black Running Shoes - 5 UK/India (38 EU)(5396053)</p>
<p>Power Women's Attract L Black Running Shoes - 5 UK/India (38 EU)(5396053)</p>
<p>Power Women's Attract L Black Running Shoes - 5 UK/India (38 EU)(5396053)</p>
<p>Power Women's Attract L Black Running Shoes - 5 UK/India (38 EU)(5396053)</p>
<jsp:include page="my-footer.jsp" />
</body>
@raunakhajela
raunakhajela / builtin-test.jsp
Created January 11, 2018 07:13
JSP: Built In Server Objects
<!--"request" object contains HTTP request headers and form data-->
<html>
<body>
<h3>JSP Built-In Objects</h3>
Request user agent: <%= request.getHeader("User-Agent") %>
<br/><br/>
Request language: <%= request.getLocale() %>
@raunakhajela
raunakhajela / FunUtils.java
Created January 11, 2018 07:09
JSP: Call Java Class from JSP
/*To create a package go to Java Resources/src right click and click new and choose "Package" and provide your package name*/
/*To create your class right click on your created package, click New and choose "Class"*/
package com.jspDemo.jsp;
public class FunUtils {
public static String makeItLower(String data){
return data.toLowerCase();
}
@raunakhajela
raunakhajela / declarations-test.jsp
Created January 11, 2018 07:01
JSP: Declarations
<!--They allow us to declare a method in the JSP page. You can call the method in the same JSP page-->
<html>
<body>
<%!
String makeItLower(String data){
return data.toLowerCase();
}
%>
Lower case "Hello World": <%= makeItLower("Hello World") %>