Show Menu
Cheatography

JSP Helper Cheat Sheet by

JSP Helper

Imports in HTML

<%@ page import­="pa­cka­geN­ame.Cl­ass­" %>
<%@ page import­="ja­va.t­ex­t.D­eci­mal­For­mat­" %>
<%@ page import­="ja­va.s­ql.*" %>
<%@ page import­="ja­va.u­ti­l.*­" %>
<js­p:i­nclude page="d­ate.js­p" flush=­"­tru­e" />

Data Typs

All Java Datatyps ( Integer, String, etc. )
ResultSet rsName; // rsName.ge­tSt­rin­g("N­ame­");

Date Handling

Date createTime = new Date();
"­" + date.t­oSt­ring() + "­"
<p>­Today´s Date: <%= ( new java.u­til.Date() ) %> </p>

Functi­on/­Methode Deklar­ation

public method­Name( String method­Par­ameter ) { method Operation }
 

JSP-Va­riable Deklar­ation between HTML

<%! String variab­leName; %>
<%! float functi­onN­ame­(String functi­onP­ara­meter){ function Operation } %>

JSP-Al­loc­ation between HTML

<% code fragment %>

JSP-Output between HTML

<form action­="<%= reques­t.g­etR­equ­est­URI() %>" method­="po­st">
<% out.pr­int­("<a href='­che­ckb­ox.j­sp­'>Z­ur&uu­ml;­ck<­/a>­"); %>

Request Operat­ionen: // GET und POST

reques­t.g­etP­ara­met­er(­"­che­ckB­oxN­ame­");
String [] variab­leName = reques­t.g­etP­ara­met­erV­alu­es(­"­che­ckB­oxN­ame­");

Response Operat­ionen:

respon­se.s­en­dRe­dir­ect­("re­dir­ect­Pag­eNa­me.j­sp­");
respon­se.a­dd­Cookie( cookie );
 

Sessions Deklar­ation

sessio­n.s­etA­ttr­ibu­te(­"­Ind­exN­ame­", "­Ind­exV­alu­e");
sessio­n.s­etM­axI­nac­tiv­eIn­ter­val­(time);

Sessions Usage

sessio­n.g­etA­ttr­ibu­te(­"­Ind­exN­ame­", object value);
sessio­n.g­etId();
sessio­n.g­etA­ttr­ibu­te();
sessio­n.g­etA­ttr­ibu­teN­ames();
sessio­n.r­emo­veA­ttr­ibu­te();
sessio­n.g­etC­rea­tio­nTi­me();
sessio­n.g­etL­ast­Acc­ess­edT­ime();
sessio­n.i­sNew();

Enumar­ations

Enumeration e = request.getParameterNames();
	String name, wert;
	while( e.hasMoreElements()) {
		name = e.nextElement().toString();
		// name = (String) e.nextElement();
		wert = request.getParameter(name);
		if ( !name.equals("submit") && !wert.equals(""))
			out.println(name + ":" + wert + "<br>");
	}
 

Cookies Deklar­ation

Cookie cookie = new Cookie("IndexName", IndexValue); 
cookie.setMaxAge(246060); // 24 Stunden
response.addCookie( cookie );

Cookie Usage

Cookie[] cookies = request.getCookies();
for(int i = 0; i < cookies.length; i++){
    Cookie c = cookies[i];
    if(c.getName().equals("name")){
          out.println("Name= " + c.getValue() );
    }
}

Compare

== | != | etc.
user.e­qua­ls(­user_f)

Cookie Delete

cookie.se­tMa­xAg­e(0);

Comments

<!-- comment --> // HTML Comment
<%-- comment --%> // JSP Comment

Exception

catch(Exception e){
		e.getMessage();
	}
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          More Cheat Sheets by Kemmojoo

          MySQL Cheat Sheet