下面列出了javax.servlet.jsp.JspWriter#print ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public int doEndTag() throws JspTagException {
JspWriter out = null;
try {
out = this.pageContext.getOut();
out.print(end().toString());
out.flush();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
out.clear();
out.close();
} catch (Exception e2) {
}
}
return EVAL_PAGE;
}
/** {@inheritDoc}
* @throws JspException JSP exception
*/
public int doStartTag() throws JspException {
if (!icons.containsKey(type)) {
throw new IllegalArgumentException("Unknown icon type: \"" + type + "\".");
}
JspWriter out = null;
try {
out = pageContext.getOut();
String result = renderStartTag();
out.print(result);
}
catch (IOException ioe) {
throw new JspException("IO error writing to JSP file:", ioe);
}
return SKIP_BODY;
}
/**
* {@inheritDoc}
*/
public int doEndTag() throws JspException {
JspWriter out = null;
try {
out = pageContext.getOut();
if (!showHeader()) {
if (showUrl()) {
out.print(href.renderCloseTag());
}
out.print(td.renderCloseTag());
}
return Tag.EVAL_BODY_INCLUDE;
}
catch (IOException ioe) {
throw new JspException("IO error writing to JSP file:", ioe);
}
}
@Override
public int doEndTag() throws JspException {
JspWriter out = pageContext.getOut();
try {
if (!"-1".equals(objectValue)) {
out.print(objectValue);
} else if (!"-1".equals(stringValue)) {
out.print(stringValue);
} else if (longValue != -1) {
out.print(longValue);
} else if (doubleValue != -1) {
out.print(doubleValue);
} else {
out.print("-1");
}
} catch (IOException ex) {
throw new JspTagException("IOException: " + ex.toString(), ex);
}
return super.doEndTag();
}
public int doEndTag() throws JspException {
String src = BasicUtil.nvl(value,body,"").toString().trim();
if(BasicUtil.isEmpty(src)){
return EVAL_BODY_INCLUDE;
}
if(null == from || from.length()==0){
return EVAL_BODY_INCLUDE;
}
if(BasicUtil.isEmpty(to)){
to = "";
}
JspWriter writer = null;
try {
writer = pageContext.getOut();
writer.print(src.replace(from, to));
} catch (IOException e) {
e.printStackTrace();
}finally{
release();
}
return EVAL_PAGE;// 标签执行完毕之后继续执行下面的内容
}
public int doEndTag() throws JspTagException {
JspWriter out = null;
try {
out = this.pageContext.getOut();
out.print(end().toString());
out.flush();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
out.clear();
out.close();
} catch (Exception e2) {
}
}
return EVAL_PAGE;
}
/**
* {@inheritDoc}
*/
@Override
public void doTag() throws JspException, IOException {
JspWriter out = getJspContext().getOut();
StringBuilder buffer = new StringBuilder();
for (String key : MessageContext.MESSAGES_KEY) {
Messages messages = extractMessagesAsList(key);
if (messages != null && !messages.isEmpty()) {
switch (messages.getMessageType()) {
case ERROR:
printMessages(buffer, messages.getMessageItemList(), ERROR_PREFIX, ERROR_SUFFIX);
break;
case INFORMATION:
printMessages(buffer, messages.getMessageItemList(), INFO_PREFIX, INFO_SUFFIX);
break;
case VALIDATION:
default:
printMessages(buffer, messages.getMessageItemList(), VALIDATION_PREFIX, VALIDATION_SUFFIX);
break;
}
}
}
if (!onlyMsg && buffer.length() > 0) {
out.print(HEADER + buffer.toString() + FOOTER);
} else {
out.print(buffer.toString());
}
}
public int doEndTag() throws JspTagException {
try {
JspWriter out = this.pageContext.getOut();
out.print(end().toString());
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
return EVAL_PAGE;
}
public static void createTitle(JspWriter out,
HttpServletRequest req, String file) throws IOException{
if(file == null) file = "";
int start = Math.max(0,file.length() - 100);
if(start != 0)
file = "..." + file.substring(start, file.length());
out.print("<title>HDFS:" + file + "</title>");
}
public static boolean output(JspWriter out, Object input, String value,
String defaultValue, boolean escapeXml) throws IOException {
if (input instanceof Reader) {
char[] buffer = new char[8096];
int read = 0;
while (read != -1) {
read = ((Reader) input).read(buffer);
if (read != -1) {
if (escapeXml) {
String escaped = Util.escapeXml(buffer, read);
if (escaped == null) {
out.write(buffer, 0, read);
} else {
out.print(escaped);
}
} else {
out.write(buffer, 0, read);
}
}
}
return true;
} else {
String v = value != null ? value : defaultValue;
if (v != null) {
if(escapeXml){
v = Util.escapeXml(v);
}
out.write(v);
return true;
} else {
return false;
}
}
}
public int doEndTag() throws JspException {
try{
JspWriter out = pageContext.getOut();
out.print(DESUtil.encryptParamValue(BasicUtil.nvl(value,body,"").toString()));
}catch(Exception e){
e.printStackTrace();
}finally{
release();
}
return EVAL_PAGE;
}
public void render(ProfileElement element, PageContext context, RendererFilter filter) throws IOException {
JspWriter out = context.getOut();
ListType list = (ListType) element.getValue();
out.println("<input type=\"hidden\" name=\"" + element.getAbsoluteName() + "\" id=\"" + element.getAbsoluteName() + "\">");
out.println("<select multiple id=\"" + element.getAbsoluteName() + ".list\" size=\"5\" style=\"width: 500px\">");
for(int i=0 ; i<list.size() ; i++){
out.println("<option value='" + list.get(i) +"'>"+list.get(i)+"</option>");
}
out.println("</select>");
out.println("<a onclick=\"removeFromList('"+element.getAbsoluteName()+"');\"><image src=\"images/action-icon-delete.gif\" alt=\"Remove\"></a><br/>");
out.print("<input id=\"");
out.print(element.getAbsoluteName() + ".new");
out.print("\" type=\"text\">");
out.println("<a onclick=\"addToList('"+element.getAbsoluteName()+"');\"><image src=\"images/subtabs-add-btn.gif\" style=\"vertical-align: bottom\" alt=\"Add\"></a>");
// Set the text field.
out.println("<script>");
out.println("var val = document.getElementById('" + element.getAbsoluteName() + "').value;");
for(int i=0 ; i<list.size() ; i++){
if( i == 0) {
out.println("val = val + '" + TextUtils.escapeForHTMLJavascript(list.get(i).toString()) + "';");
}
else {
out.println("val = val + '\\n' + '" + TextUtils.escapeForHTMLJavascript(list.get(i).toString()) +"';");
}
}
out.println("document.getElementById('" + element.getAbsoluteName() + "').value = val;");
out.println("</script>");
out.println("<br/>");
}
public int doEndTag() throws JspException {
try {
JspWriter out = this.pageContext.getOut();
if (style.equals("easyui")) {
out.print(end().toString());
} else {
out.print(datatables().toString());
out.flush();
}
} catch (IOException e) {
e.printStackTrace();
}
return EVAL_PAGE;
}
public int doEndTag() throws JspTagException {
try {
JspWriter out = this.pageContext.getOut();
out.print(end().toString());
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
return EVAL_PAGE;
}
public int doEndTag() throws JspTagException {
try {
JspWriter out = this.pageContext.getOut();
out.print(end().toString());
} catch (IOException e) {
e.printStackTrace();
}
return EVAL_PAGE;
}
@Override
public void doTag() throws JspException, IOException {
JspWriter out = getJspContext().getOut();
String statusLabel = TodoListUtils.getStatusLabel(status);
out.print(statusLabel);
}
@Override
public int doStartTag() throws JspException {
JspWriter writer = pageContext.getOut();
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
Page page = (Page)request.getAttribute(bean);
if (page == null)
return SKIP_BODY;
url = resolveUrl(url, pageContext);
try {
//计算总页数
int pageCount = page.getTotal() / page.getSize();
if (page.getTotal() % page.getSize() > 0) {
pageCount++;
}
writer.print("<nav><ul class=\"pagination\">");
//显示“上一页”按钮
if (page.getPage() > 1) {
String preUrl = append(url, "page", page.getPage() - 1);
preUrl = append(preUrl, "rows", page.getSize());
writer.print("<li><a href=\"" + preUrl + "\">上一页</a></li>");
} else {
writer.print("<li class=\"disabled\"><a href=\"#\">上一页</a></li>");
}
//显示当前页码的前2页码和后两页码
//若1 则 1 2 3 4 5, 若2 则 1 2 3 4 5, 若3 则1 2 3 4 5,
//若4 则 2 3 4 5 6 ,若10 则 8 9 10 11 12
int indexPage = (page.getPage() - 2 > 0)? page.getPage() - 2 : 1;
for(int i=1; i <= number && indexPage <= pageCount; indexPage++, i++) {
if(indexPage == page.getPage()) {
writer.print( "<li class=\"active\"><a href=\"#\">"+indexPage+"<span class=\"sr-only\">(current)</span></a></li>");
continue;
}
String pageUrl = append(url, "page", indexPage);
pageUrl = append(pageUrl, "rows", page.getSize());
writer.print("<li><a href=\"" + pageUrl + "\">"+ indexPage +"</a></li>");
}
//显示“下一页”按钮
if (page.getPage() < pageCount) {
String nextUrl = append(url, "page", page.getPage() + 1);
nextUrl = append(nextUrl, "rows", page.getSize());
writer.print("<li><a href=\"" + nextUrl + "\">下一页</a></li>");
} else {
writer.print("<li class=\"disabled\"><a href=\"#\">下一页</a></li>");
}
writer.print("</nav>");
} catch (IOException e) {
e.printStackTrace();
}
return SKIP_BODY;
}
/**
* {@inheritDoc}
*/
protected void renderData(JspWriter out, ListDisplayTag parent)
throws IOException {
super.renderData(out, parent);
//Render contents of column here
HtmlTag cbox = new HtmlTag("input");
if (type == null || type.equals("checkbox")) {
cbox.setAttribute("type", "checkbox");
cbox.setAttribute("onclick", "checkbox_clicked(this, '" +
getSet().getLabel() + "')");
}
else {
cbox.setAttribute("type", "radio");
}
cbox.setAttribute("name", "items_selected");
cbox.setAttribute("value", getValue());
//Should checkbox be checked?
if (checkboxChecked()) {
cbox.setAttribute("checked", "true");
parent.incrementChecked();
}
//Should checkbox be disabled?
if (disabled) {
cbox.setAttribute("disabled", "disabled");
}
if (this.getTitle() != null) {
cbox.setAttribute("title", LocalizationService.getInstance()
.getMessage(this.getTitle()));
}
if (this.getAlt() != null) {
cbox.setAttribute("alt", LocalizationService.getInstance()
.getMessage(this.getAlt()));
}
HtmlTag hideme = new HtmlTag("input");
hideme.setAttribute("type", "hidden");
hideme.setAttribute("name", "items_on_page");
hideme.setAttribute("value", getValue());
out.print(cbox.render() + "\n" + hideme.render());
}
public int doEndTag() throws JspException {
try{
String result = null;
if(null == value){
value = body;
}
if(BasicUtil.isEmpty(value)){
value = def;
}
if(BasicUtil.isNotEmpty(value)){
BigDecimal num = new BigDecimal(value.toString());
if(BasicUtil.isNotEmpty(min)){
BigDecimal minNum = new BigDecimal(min.toString());
if(minNum.compareTo(num) > 0){
num = minNum;
log.warn("[number format][value:{}][小于最小值:{}]", num,min);
}
}
if(BasicUtil.isNotEmpty(max)){
BigDecimal maxNum = new BigDecimal(max.toString());
if(maxNum.compareTo(num) < 0){
num = maxNum;
log.warn("[number format][value:{}][超过最大值:{}]",num, max);
}
}
result = NumberUtil.format(num,format);
}else{
if(null == result && null != nvl){
result = nvl.toString();
}
if(BasicUtil.isEmpty(result) && null != evl){
result = evl.toString();
}
}
if(null != result) {
JspWriter out = pageContext.getOut();
out.print(result);
}
}catch(Exception e){
e.printStackTrace();
}finally{
release();
}
return EVAL_PAGE;
}
/**
* Actions after some body has been evaluated.
*/
@Override
public int doAfterBody() throws JspTagException {
JspWriter jspWriter;
try {
// Get the writer to output the query result.
jspWriter = getBodyContent().getEnclosingWriter();
jspWriter.print( getBodyContent().getString() );
} catch (IOException e) {
throw new NavigatorRuntimeException("Error in ForEachTag.", e);
}
// If current row is relevant to the grouping ancestor.
if (groupingAncestor != null && groupingAncestor.needsCurrentRow())
return SKIP_BODY;
// If the end of the query result has been reached.
if (!queryWrapper.hasNext())
return SKIP_BODY;
// Move to next row in query result.
queryWrapper.next();
queryWrapper.bindVariables(groupColumns);
sequenceNumber++;
// insert separating string (if any)
if (separator != null) {
try {
jspWriter.print( separator );
} catch(IOException ioe) {
throw new NavigatorRuntimeException("Error in ForEachTag.", ioe);
}
}
boolean isLast = !queryWrapper.hasNext() ||
(groupingAncestor != null && (groupingAncestor.needsCurrentRow() || queryWrapper.isOnlyChild(groupingAncestor.groupColumns, groupColumns)));
queryWrapper.getContextManager().setValue(SEQUENCE_FIRST, FALSE);
queryWrapper.getContextManager().setValue(SEQUENCE_NUMBER, Integer.toString(sequenceNumber));
queryWrapper.getContextManager().setValue(SEQUENCE_LAST, isLast ? TRUE : FALSE);
// Prepare for next iteration.
getBodyContent().clearBody();
return EVAL_BODY_AGAIN;
}