Servlet & JSP – 32 – Simple Tag Handler – 02

Merhaba Arkadaslar,
Bu yazida Simple Tag konusuna devam edecegiz. SkipPageException ‘i inceleyelim.

javax.servlet.jsp.SkipPageException

SkipPageException , javax.servlet.jsp.JspException sinifinin alt sinifidir. doTag metodunda bir problemle karsilastigimiz ilgili sarta gore SkipPageException firlatabiliriz. Bu durumda JSP sayfamizin geri kalani calistirilmaz. Eger JspException firlatilirsa bu durumda sayfamiz patlayacaktir.

SimpleTagHandler6.java

package _14_SimpleTagHandler;

import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.SkipPageException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

public class SimpleTagHandler6 extends SimpleTagSupport {

	@Override
	public void doTag() throws JspException, IOException {

		
		getJspContext().getOut().print("Hello SimpleTag Example.");
		getJspBody().invoke(null);
		
		String myValue = null;
		// ...

		if (myValue == null) {
			throw new SkipPageException();
		}
		

	}

}

simpleTag.tld

	<tag>
		<name>mySimpleTagName6</name>
		<tag-class>_14_SimpleTagHandler.SimpleTagHandler6</tag-class>
		<body-content>scriptless</body-content>
	</tag>

simpleTag6.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib uri="mySimpleTagURI" prefix="myTags6"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello SimpleTag5</title>
</head>
<body>

	<p>Before simple tag call</p>

	<myTags6:mySimpleTagName6>
		<p>simple tag body</p>
	</myTags6:mySimpleTagName6>

	<p>after simple tag call. not works !</p>

</body>
</html>

Simple Tag icerisinde SkipPageException firlatildiginda , tag sonrasindaki kisim calismaz.
simpleTag6.jsp sayfasini baska bir JSP sayfasina eklersek ;

simpleTag7.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib uri="mySimpleTagURI" prefix="myTags6"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello SimpleTag5</title>
</head>
<body>

	<p>before include page</p>
	<jsp:include page="simpleTag6.jsp"></jsp:include>
	<p>after include page</p>

</body>
</html>

SkipPageExceptions sadece simpleTag6.jsp sayfasini etkileyecektir. simpleTag6.jsp sayfasini ekledigimiz (include) simpleTag7.jsp sayfasi normal sekilde calisacaktir.

Yazimi burada sonlandiriyorum.
Herkese Bol Javali Gunler dilerim.
Be an oracle man , import java.*;
Levent Erguder
OCP, Java SE 6 Programmer
OCE, Java EE 6 Web Component Developer

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *