Created
August 25, 2015 02:51
-
-
Save mattkruskamp/7b12e646429a837d4ce3 to your computer and use it in GitHub Desktop.
J2EE Custom Simple Tags Part 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.cyberkruz.test; | |
import java.io.*; | |
import javax.servlet.jsp.*; | |
import javax.servlet.jsp.tagext.SimpleTagSupport; | |
public class NewMath extends SimpleTagSupport { | |
private Integer num; | |
/** | |
* Method overridden which is called | |
* by the jsp. | |
*/ | |
public void doTag() throws JspException, IOException { | |
// Gets the jsp context and prints the | |
// number squared. | |
this.getJspContext().getOut().print(this.num * this.num); | |
} | |
/** | |
* Sets a number that our custom | |
* tag squares. | |
* @param num The number to which | |
* we want to square. | |
*/ | |
public void setNum(Integer num) { | |
this.num = num; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@page language=“java” | |
contentType=“text/html; charset=ISO-8859-1” | |
pageEncoding=“ISO-8859-1”%> | |
<%@ taglib=“” prefix=“math” uri=“myTags” %> | |
<html> | |
<head> | |
<title>SimpleTest</title> | |
<meta http-equiv=“Content-Type” content=“text/html; charset=ISO-8859-1”> | |
</head> | |
<body> | |
10 squared is: <math:Square num=“10” />. | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment