WebObjects/Web 应用程序/开发/示例/锚点
外观
将以下内容放在组件的超类中
private String anchor; public void appendToResponse(WOResponse response, WOContext context) { if (anchor != null) { response.setHeader(context.componentActionURL() + "#" + anchor, "location"); response.setHeader("text/html", "content-type"); response.setHeader("0", "content-length"); response.setStatus(302); anchor = null; } else { super.appendToResponse(response, context); } } // appendToResponse
public String getAnchor() { return anchor; } public void setAnchor(String s) { anchor = s; }
在我们要使用锚点的组件中,只需输入
<a name="myanchor"></a>
以及在我们要跳转到此锚点的代码中输入类似以下内容
protected WOComponent doSometingAndJumpToAnchor() { // do something :) setAnchor("myanchor"); return null; }