📄 departmenttag.java
字号:
package tld;
import javax.servlet.jsp.JspException;
import java.io.IOException;
import src.wuyang.*;
public class DepartmentTag extends javax.servlet.jsp.tagext.TagSupport{
String showType = "select";
String deptId = "";
public void setShowType(String aShowType) {
showType = aShowType.toLowerCase();
}
public void setDeptId(String aDeptId) {
deptId = aDeptId;
}
/**
* Executes when the tag is started.
*/
public int doStartTag() throws JspException {
return SKIP_BODY;
}
/**
* Executed with the end tag.
*/
public int doEndTag() throws JspException {
try {
//pageContext.getOut().print("<h2>Hello from doStartTag()</h2>");
// Allowtext in the body of the tag
Department dept = new Department();
if(showType.equals("select")){
dept.query("","");
pageContext.getOut().print("<option value=\"" + "\">" + " " + "</option>");
while(dept.next()== 1 ) {
pageContext.getOut().print("<option value=\"" + dept.getDeptId() + "\">" + dept.getDeptName() + "</option>");
}
}
else if(showType.equals("get")){
dept.load(deptId);
System.out.println(deptId);
System.out.println(showType);
if (deptId.equals("0")) {
pageContext.getOut().print("总公司");
} else if (dept.getDeptName()==null) {
pageContext.getOut().print("");
} else {
pageContext.getOut().print(dept.getDeptName());
}
}
else if(showType.equals("select2")){
dept.query("","");
while(dept.next()== 1 ) {
if (dept.getDeptId().equals(deptId))
pageContext.getOut().print("<option value=\"" + dept.getDeptId() + "\" selected >" + dept.getDeptName() + "</option>");
else
pageContext.getOut().print("<option value=\"" + dept.getDeptId() + "\">" + dept.getDeptName() + "</option>");
}
}
return EVAL_BODY_INCLUDE;
} catch (IOException e){
throw new javax.servlet.jsp.JspException(e.getMessage());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -