JSP accepting String[] as attribute to custom tag
Hi viewers In the below example I'm giving you the code samples that i have done for this taskStep 1: Create a dynamic web project in your eclipse
Step 2: create a package with any of your desired name say com.practice.customtags
Step 3: Create a java class with some name say SimpleTag.Java
package com.pratice.customtags;
import java.io.IOException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
public class SimpleTag extends TagSupport {
private static final long serialVersionUID = 6997517813033042928L;
private String[] input;
public int doEndTag(){
JspWriter out =pageContext.getOut();
try {
for(int i=0;i<input .length;i++){
out.println(input[i]);
}
} catch (IOException e) {
e.printStackTrace();
}
return EVAL_PAGE;
}
public String[] getInput() {
return input;
}
public void setInput(String[] input) {
this.input = input;
}
}
Step 4: Create a new file with and save as custom.tld in your eclipse .save it under
WebContent/WEB-INF/custom.tld
WebContent/WEB-INF/custom.tld
1.0 2.0 Example TLD ObjectArray com.pratice.customtags.SimpleTag input true java.lang.String[] true false
Step 5: Create a jsp file index.jsp under WebContent folder of your dynamic web application
<%@ taglib prefix="My" uri="WEB-INF/custom.tld"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%String[] check={"naveen","rajesh","vivek"}; %>
Step: And Finally run the web application you will see the output as
naveen
rajesh vivek Thanks and Regards Naveen
rajesh vivek Thanks and Regards Naveen
No comments:
Post a Comment