0
我正在嘗試使用自定義標記來編寫我的頁腳。我對此很陌生,我想讓MyFooterTag類更具可讀性。在MyFooterTag類中,我向JspWriter寫入沒有主體和屬性的所有東西,但它看起來不太可讀...有沒有一種方法可以使用主體內容或屬性來優化它?具有屬性的JSP自定義標記
<footer class="container-fluid text-center">
<p><fmt:message key="online_store.copyright.footer"></fmt:message></p>
<form class="form-inline"><fmt:message key="get_deals.footer"></fmt:message>
<input type="email" class="form-control" size="50" placeholder="Email Address">
<button type="button" class="btn btn-danger"><fmt:message key="sign_up.footer"></fmt:message></button>
</form>
</footer>
private final static String bootstrapFooterClass = "container-fluid text-center";
private final static String bootstrapFormClass = "form-inline";
private final static String bootstrapInputClass = "form-control";
private final static String bootstrapButtonClass = "btn btn-danger";
private final static String footerCopyrightKey = "online_store.copyright.footer";
private final static String getDealsFooterKey = "get_deals.footer";
private final static String singUpFooterKey = "sing_up.footer";
@Override
public int doStartTag() throws JspException {
String footerStart = "<footer class='" + bootstrapFooterClass + "'>";
String copyright = "<p><fmt:message key='" + footerCopyrightKey + "'></fmt:message>";
String form = "<form class='" + bootstrapFormClass + "'><fmt:message key='" + getDealsFooterKey + "'></fmt:message>";
String input = "<input type='email' class='" + bootstrapInputClass + "' size='50' placeholder='Email Address'>";
String button = "<button type='button' class='" + bootstrapButtonClass + "'><fmt:message key='" + singUpFooterKey + "'></fmt:message></button>";
try{
JspWriter out = pageContext.getOut();
out.write(footerStart);
out.newLine();
out.write(copyright);
out.newLine();
out.write(form);
out.newLine();
out.write(input);
out.newLine();
out.write(button);
}catch (IOException e){
throw new JspException(e.toString());
}
return SKIP_BODY;
}
@Override
public int doEndTag() throws JspException {
String endTags = "</form></footer>";
try {
pageContext.getOut().write(endTags);
} catch (IOException e) {
throw new JspTagException(e.toString());
}
return EVAL_PAGE;
}
嘿@亞歷山大你檢查我的答案或不! – PacMan