定义标记错误2
package text;
/**
* @author 让痛苦痛苦
* 用确认标记预防错误
*/
/**
* 下面的一个自定义标记,用于获得下拉列表框的返回值,功能等价于javascript
* 由于下拉列表框的称谓比较长,部分借助 JavaScriptDropdownRequiredValidationTag 代码的
*/
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import javax.servlet.http.HttpSession;
import javax.sound.sampled.Line;
import javax.swing.plaf.SliderUI;
import com.sun.org.apache.bcel.internal.generic.NEWARRAY;
import java.io.*;
public class JavaScritDropDownRequiresTag extends TagSupport {
private String strLineSep=System.getProperty("Line.separator");
private String jSRequireTextTag="if(document.?[document..?.selectedIndex].value.lenth"+"==0)"+strLineSep+"{"+strLineSep+"alert(/"? is a required field/"};"+strLineSep+"return;"+strLineSep+"}";
private String alertGUIName="";
private String foemAndInputName="";
public void setAlertGUIName(String NewAlertGUIName)
{
if(NewAlertGUIName!=null)
{
alertGUIName=NewAlertGUIName.trim();
}
}
public void setFormAndInputName(String NewFormAndInputName)
{
if(NewFormAndInputName!=null)
{
foemAndInputName=NewFormAndInputName.trim();
}
}
public int doEndTag()
{
try {
String sBrowserVersion="";
try {
HttpSession hs=pageContext.getSession();
sBrowserVersion=(String)hs.getAttribute("User-Agent");
System.out.println("User-Agent found:"+sBrowserVersion);
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
String strJs=SpliceParameter(jSRequireTextTag,foemAndInputName);
strJs=SpliceParameter(strJs,foemAndInputName);
strJs=SpliceParameter(strJs,alertGUIName);
pageContext.getOut().println(strJs);
} catch (IOException ioe) {
ioe.printStackTrace();
// TODO: handle exception
}
return TagSupport.EVAL_PAGE;
}
public static String SpliceParameter(String sStringBody,String sParameter)
{
if(sStringBody==null)
{
sStringBody="";
}
if(sParameter==null)
{
sParameter="";
}
StringBuffer sb=new StringBuffer(sStringBody.length()+sParameter.length());
sb.append(sStringBody);
int iPositionQuestionMark=sStringBody.indexOf("?");
if(iPositionQuestionMark!=-1)
{
sb.replace(iPositionQuestionMark, iPositionQuestionMark+1, sParameter);
return sb.toString();
}
else
{
return sStringBody;
}
}
/**
* JavaScritDropDownRequiresTag源自一个确认类,它实现了isValid方法。扩充了TagExtraInfo类的功能
* 有了检查功能,自定义标记的可靠性可以大大提高
*/
}