Friday 29 November 2013

JSP accepting String[] as attribute to custom tag

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 task

Step 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
 
   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

Monday 25 November 2013

About Me

      Hi I'm Naveen. I am a Software developer and a beginner.I created this blog to do simple coding exercises. Write some technical stuff in this blog which helps me and other developers in their daily coding tasks .If you like my posts click like and post your feedback in the below comment box.You can contact me at venkatanaveen.iter@gmail.com



                                 Thanks and reagrds
                                  Naveen...........................