读书人

XML+XSL 中静态链接 的兑现

发布时间: 2012-09-16 17:33:17 作者: rapoo

XML+XSL 中静态链接 的实现

刚接触XSL,多少有些不习惯,容易用html的思路想问题。这本没错!可是对于一些最基本的链接功能<a href=""></a>在XSL中如何实现呢?

如在index.xsl中有<a title="login" href="msg.jw?act=loginhref">login</a>

则程序将转到memberCtrlServlet类中执行

protected void execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
String action=getAction(request);
if if(action.equals("loginhref"))
{
jumpToLogin(request, response);
}

}



private void jumpToLogin(HttpServletRequest request, HttpServletResponse response) throws Exception{

String xml=getEmptyXml();
String result=transformByXsl(request, xml, XSL_PATH_MESSAGE_login);
outputXml(response, result);
}


protected String getAction(HttpServletRequest request) {
WebStringUtil webStringUtil=WebStringUtil.getInstance();
String pathInfo=request.getPathInfo();
String action=webStringUtil.getString(request, "act");

if(action == null || action.length() == 0) {
if(pathInfo != null && pathInfo.length() > 0) {
action=pathInfo.substring(1, pathInfo.indexOf('/', 1));
}
}

return action;
}

什么意思呢? 就是 index.xsl将请求msg.jw?act=loginhref"抛给servlet让servlet实现跳转!



读书人网 >XML SOAP

热点推荐