Topic: 怎样让网站支持theme/skin?

  Print this page

1.怎样让网站支持theme/skin? Copy to clipboard
Posted by: wuliang
Posted on: 2004-11-23 21:15

根据用户设置的theme,将请求转发到skins下相应目录
比如:/index.jsp?theme=blue => /skins/blue/index.jsp
(theme也可能从cookie里获取)

不是css那种,需要转到不同页面的,有这样的框架吗?
主要是结合struts,tiles用

谢谢!

2.Re:怎样让网站支持theme/skin? [Re: wuliang] Copy to clipboard
Posted by: wuliang
Posted on: 2004-11-23 21:22

我自己写了个ThemeServlet,用RequestDispatcher,将请求根据theme设置转发到相应skins目录
/pages/greeting.jsp => /skins/default/greeting.jsp
/pages/greeting.jsp?theme=blue => /skins/blue/greeting.jsp

其中/pages是ThemeServlet处理的目录:

<servlet-mapping>
<servlet-name>themeServlet</servlet-name>
<url-pattern>/pages/*</url-pattern>
</servlet-mapping>


如果是和struts action结合,这样映射
/greeting.do =(actionForward)=> /pages/greeting.jsp =(forwarded by themeServlet)=> /skins/default/greeting.jsp
也很正常


但是,如果用struts tiles,却不能显示内容?

home.jsp:
<tiles:insert definition="homeLayout">
<tiles:put name="top" value="/skins/default/greeting.jsp" />
<tiles:put name="bottom" value="/greeting.do" />
</tiles:insert>

*top部分,能正常插入greeting.jsp的内容,bottom部分不行

应该怎么修改ThemeServlet呢?

ThemeServlet.jsp

private String trapFolder = "/pages";
private String skinsFolder = "/skins";

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String uri = request.getRequestURI();
String context = request.getContextPath();
String path = uri.substring(context.length());
if (path.startsWith(skinsFolder)) {
// RequestDispatcher rd = request.getRequestDispatcher(path);
// rd.include(request, response);
return;
}

path = path.substring(trapFolder.length());

String themeName = request.getParameter("theme");
if (themeName == null || themeName.length() == 0)
themeName = "default";


String page = skinsFolder + "/" + themeName + path;

RequestDispatcher rd = request.getRequestDispatcher(page);
rd.include(request, response);
}


附件是eclipse3项目文件,没有包括struts lib文件

mytheme.rar (17.83k)

3.Re:怎样让网站支持theme/skin? [Re: wuliang] Copy to clipboard
Posted by: daviszw
Posted on: 2004-12-06 13:11

用htc可以实现网站的皮肤更换

4.Re:怎样让网站支持theme/skin? [Re: wuliang] Copy to clipboard
Posted by: hawker
Posted on: 2004-12-06 21:53

看一看Weblogic Portal的设计,将一个页面的展示通过多个视图体现,每一个小的视图包括一个标题,一个框架和一个背景,然后使用统一的一个渲染组件根据用户需要的skin进行渲染,这样就可以实现了。


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923