⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formoptiontaghandler.java

📁 使用Servlet和JSP进行Web组件开发
💻 JAVA
字号:
package sl314.taglib;

// Servlet imports
import javax.servlet.jsp.tagext.SimpleTagSupport;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.JspException;
import javax.servlet.ServletRequest;
import java.io.IOException;


/**
 * This class handles the "select" form tag.
 */
public class FormOptionTagHandler extends SimpleTagSupport {

  private String value;

  public void setValue(String value) {
    this.value = value;
  }

  public void doTag() throws JspException, IOException {
    PageContext pageContext = (PageContext) getJspContext();
    ServletRequest request = pageContext.getRequest();
    JspWriter out = pageContext.getOut();

    // Retrieve the value of the parameter (set by the 'select' tag)
    FormSelectTagHandler parentTag
        = (FormSelectTagHandler) findAncestorWithClass(this,
                                                       FormSelectTagHandler.class);
    String paramValue = parentTag.getParamValue();

    // Start the HTML 'option' tag
    out.print("<option value='");
    out.print(value);
    out.print('\'');

    // Include the SELECTED attribute if necessary
    if ( value.equals(paramValue) ) {
      out.print(" selected");
    }

    // Close the start tag
    out.print('>');

    // Include the body of the tag
    getJspBody().invoke(null);

    // Close the HTML 'option' tag
    out.println("</option>");
  }

} // end of FormOptionTagHandler class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -