对jsp网页布局

lsmsilence 2009-12-02 09:53:50
我有一段JSP写的网页,里面用了大量的标签,但是我现在想在整个网页外加一个大表格,是整个网页不占满整个屏幕,而是按照宽度为1003像素固定显示,但是用表格不行,请问应该怎么弄?
代码如下,我也不知道用没用框架,好像没用,但是左边的导航栏始终控制不了宽度
<%--
- home.jsp

--%>

<%@ page contentType="text/html;charset=UTF-8" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<%@ taglib uri="http://www.dspace.org/dspace-tags.tld" prefix="dspace" %>

<%@ page import="java.io.File" %>
<%@ page import="java.util.Enumeration"%>
<%@ page import="java.util.Locale"%>
<%@ page import="javax.servlet.jsp.jstl.core.*" %>
<%@ page import="javax.servlet.jsp.jstl.fmt.LocaleSupport" %>
<%@ page import="org.dspace.core.I18nUtil" %>
<%@ page import="org.dspace.app.webui.util.UIUtil" %>
<%@ page import="org.dspace.content.Community" %>
<%@ page import="org.dspace.core.ConfigurationManager" %>
<%@ page import="org.dspace.browse.ItemCounter" %>

<%
Community[] communities = (Community[]) request.getAttribute("communities");

Locale[] supportedLocales = I18nUtil.getSupportedLocales();
Locale sessionLocale = UIUtil.getSessionLocale(request);
Config.set(request.getSession(), Config.FMT_LOCALE, sessionLocale);
String topNews = ConfigurationManager.readNewsFile(LocaleSupport.getLocalizedMessage(pageContext, "news-top.html"));
String sideNews = ConfigurationManager.readNewsFile(LocaleSupport.getLocalizedMessage(pageContext, "news-side.html"));

boolean feedEnabled = ConfigurationManager.getBooleanProperty("webui.feed.enable");
String feedData = "NONE";
if (feedEnabled)
{
feedData = "ALL:" + ConfigurationManager.getProperty("webui.feed.formats");
}

ItemCounter ic = new ItemCounter(UIUtil.obtainContext(request));
%>

<dspace:layout locbar="nolink" titlekey="jsp.home.title" feedData="<%= feedData %>"><这里用了layout标签,该标签有很多属性>我在下面贴出这个的源码

<table width="95%" align="center">
<tr align="right">
<td align="right">
<% if (supportedLocales != null && supportedLocales.length > 1)
{
%>
<form method="get" name="repost" action="">
<input type ="hidden" name ="locale"/>
</form>
<%
for (int i = supportedLocales.length-1; i >= 0; i--)
{
%>
<a class ="langChangeOn"
onclick="javascript:document.repost.locale.value='<%=supportedLocales[i].toString()%>';
document.repost.submit();">
<%= supportedLocales[i].getDisplayLanguage(supportedLocales[i])%>
</a>  
<%
}
}
%>
</td>
</tr>
<!--
<tr>
<td class="oddRowEvenCol"><%= topNews %></td>
</tr>
-->
</table>
<br/>
<!-- <form action="<%= request.getContextPath() %>/simple-search" method="get">
<table class="miscTable" width="95%" align="center">
<tr>
<td class="oddRowEvenCol">
<h3><fmt:message key="jsp.home.search1"/></h3>
<p><label for="tquery"><fmt:message key="jsp.home.search2"/></label></p>
<p><input type="text" name="query" size="20" id="tquery" /> 
<input type="submit" name="submit" value="<fmt:message key="jsp.general.search.button"/>" /></p>
</td>
</tr>
</table>
</form> -->
<table class="miscTable" width="95%" align="center">
<tr>
<td class="oddRowEvenCol">
<h3><fmt:message key="jsp.home.com1"/></h3>
<p><fmt:message key="jsp.home.com2"/></p>


<%
if (communities.length != 0)
{
%>
<table border="0" cellpadding="2">
<%

for (int i = 0; i < communities.length; i++)
{
%> <tr>
<td class="standard">
<a href="<%= request.getContextPath() %>/handle/<%= communities[i].getHandle() %>"><%= communities[i].getMetadata("name") %></a>
<%
if (ConfigurationManager.getBooleanProperty("webui.strengths.show"))
{
%>
[<%= ic.getCount(communities[i]) %>]
<%
}

%>
</td>
</tr>
<%
}
%>
</table>
<%
}
%>

</td>
</tr>
</table>

<dspace:sidebar>
<dspace:include page="/components/login-form.jsp" />
<!--
<%= sideNews %>
<%
if(feedEnabled)
{
%>
<center>
<h4><fmt:message key="jsp.home.feeds"/></h4>
<%
String[] fmts = feedData.substring(feedData.indexOf(':')+1).split(",");
String icon = null;
int width = 0;
for (int j = 0; j < fmts.length; j++)
{
if ("rss_1.0".equals(fmts[j]))
{
icon = "rss1.gif";
width = 80;
}
else if ("rss_2.0".equals(fmts[j]))
{
icon = "rss2.gif";
width = 80;
}
else
{
icon = "rss.gif";
width = 36;
}
%>
<a href="<%= request.getContextPath() %>/feed/<%= fmts[j] %>/site"><img src="<%= request.getContextPath() %>/image/<%= icon %>" alt="RSS Feed" width="<%= width %>" height="15" vspace="3" border="0" /></a>
<%
}
%>
</center>
<%
}
%>
-->
</dspace:sidebar>

</dspace:layout>







...全文
572 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
moochyep 2009-12-23
  • 打赏
  • 举报
回复
不需要在外边加一个table。想必你也在研究Dspace吧。
方法是把/webapps/jspui/下的styles.css.jsp文件打开,
BODY{...}中添加width:1003px;(我更喜欢960px)
对照修改: margin:auto;
注释掉这两行:/* margin-left:0px;
margin-right:0px;*/
就可以了。
另外,请问您在哪个单位呀?
lsmsilence 2009-12-02
  • 打赏
  • 举报
回复
// Navigation bar: "default" is default :)
if (navbar == null)
{
navbar = "default";
}

if (navbar.equals("off"))
{
request.setAttribute("dspace.layout.navbar", "off");
}
else
{
request.setAttribute("dspace.layout.navbar", "/layout/navbar-"
+ navbar + ".jsp");
}

// Set title
if (title != null)
{
request.setAttribute("dspace.layout.title", title);
}
else if (titleKey != null)
{
request.setAttribute("dspace.layout.title", LocaleSupport
.getLocalizedMessage(pageContext, titleKey));
}
else
{
request.setAttribute("dspace.layout.title", "NO TITLE");
}

// Set feedData if present
if (feedData != null && ! "NONE".equals(feedData))
{
// set the links' reference - community or collection
boolean commLinks = feedData.startsWith("comm:");
boolean collLinks = feedData.startsWith("coll:");
if ( commLinks )
{
Community com = (Community)request.getAttribute("dspace.community");
request.setAttribute("dspace.layout.feedref", com.getHandle());
}
else if( collLinks )
{
Collection col = (Collection)request.getAttribute("dspace.collection");
request.setAttribute("dspace.layout.feedref", col.getHandle());
}
else //feed is across all of DSpace and not Community/Collection specific
{
request.setAttribute("dspace.layout.feedref", FeedServlet.SITE_FEED_KEY);
}

// build a list of link attributes for each link format
String[] formats = feedData.substring(feedData.indexOf(":")+1).split(",");
List linkParts = new ArrayList();
// each link has a mime-type, title, and format (used in href URL)
for (int i = 0; i < formats.length; i++)
{
if("rss_1.0".equals(formats[i]))
{
linkParts.add("rdf+xml");
}
else
{
linkParts.add("rss+xml");
}

if (commLinks)
{
linkParts.add("Items in Community");
}
else if(collLinks)
{
linkParts.add("Items in Collection");
}
else
{
linkParts.add("Items in " + ConfigurationManager.getProperty("dspace.name"));
}

linkParts.add(formats[i]);
}
request.setAttribute("dspace.layout.linkparts", linkParts);
}
else
{
request.setAttribute("dspace.layout.feedref", "NONE" );
}

// Now include the header
try
{
HttpServletResponse response = (HttpServletResponse) pageContext
.getResponse();

// Set headers to prevent browser caching, if appropriate
if ((noCache != null) && noCache.equalsIgnoreCase("true"))
{
response.addDateHeader("expires", 1);
response.addHeader("Pragma", "no-cache");
response.addHeader("Cache-control", "no-store");
}

// Ensure the HTTP header will declare that UTF-8 is used
// in the response.
response.setContentType("text/html; charset=UTF-8");

ServletConfig config = pageContext.getServletConfig();

RequestDispatcher rd = config.getServletContext()
.getRequestDispatcher(header);

rd.include(request, response);
}
catch (IOException ioe)
{
throw new JspException("Got IOException: " + ioe);
}
catch (ServletException se)
{
log.warn("Exception", se.getRootCause());
throw new JspException("Got ServletException: " + se);
}

return EVAL_BODY_INCLUDE;
}

public int doEndTag() throws JspException
{
// Footer file to use
String footer = "/layout/footer-default.jsp";

// Choose default flavour unless one is specified
if (style != null)
{
footer = "/layout/footer-" + style.toLowerCase() + ".jsp";
}

try
{
// Ensure body is included before footer
pageContext.getOut().flush();

// Context objects
ServletRequest request = pageContext.getRequest();
ServletResponse response = pageContext.getResponse();
ServletConfig config = pageContext.getServletConfig();

if (sidebar != null)
{
request.setAttribute("dspace.layout.sidebar", sidebar);
}

RequestDispatcher rd = config.getServletContext()
.getRequestDispatcher(footer);

rd.include(request, response);
}
catch (ServletException se)
{
throw new JspException("Got ServletException: " + se);
}
catch (IOException ioe)
{
throw new JspException("Got IOException: " + ioe);
}

return EVAL_PAGE;
}

/**
* Get the value of title.
*
* @return Value of title.
*/
public String getTitle()
{
return title;
}

/**
* Set the value of title.
*
* @param v
* Value to assign to title.
*/
public void setTitle(String v)
{
this.title = v;
}

/**
* @return Returns the titleKey.
*/
public String getTitlekey()
{
return titleKey;
}

/**
* @param titleKey The titleKey to set.
*/
public void setTitlekey(String titleKey)
{
this.titleKey = titleKey;
}

/**
* Get the value of navbar.
*
* @return Value of navbar.
*/
public String getNavbar()
{
return navbar;
}

/**
* Set the value of navbar.
*
* @param v
* Value to assign to navbar.
*/
public void setNavbar(String v)
{
this.navbar = v;
}

/**
* Get the value of locbar.
*
* @return Value of locbar.
*/
public String getLocbar()
{
return locbar;
}

/**
* Set the value of locbar.
*
* @param v
* Value to assign to locbar.
*/
public void setLocbar(String v)
{
this.locbar = v;
}

/**
* Get the value of parentTitle.
*
* @return Value of parentTitle.
*/
public String getParenttitle()
{
return parentTitle;
}

/**
* Set the value of parent.
*
* @param v
* Value to assign to parent.
*/
public void setParenttitle(String v)
{
this.parentTitle = v;
}

/**
* get parent title key (from message dictionary)
*
* @return Returns the parentTitleKey.
*/
public String getParenttitlekey()
{
return parentTitleKey;
}

/**
* set parent title key (from message dictionary)
*
* @param parentTitleKey The parentTitleKey to set.
*/
public void setParenttitlekey(String parentTitleKey)
{
this.parentTitleKey = parentTitleKey;
}

/**
* Get the value of parentlink.
*
* @return Value of parentlink.
*/
public String getParentlink()
{
return parentLink;
}

/**
* Set the value of parentlink.
*
* @param v
* Value to assign to parentlink.
*/
public void setParentlink(String v)
{
this.parentLink = v;
}

/**
* Get the value of style.
*
* @return Value of style.
*/
public String getStyle()
{
return style;
}

/**
* Set the value of style.
*
* @param v
* Value to assign to style.
*/
public void setStyle(String v)
{
this.style = v;
}

/**
* Get the value of sidebar.
*
* @return Value of sidebar.
*/
public String getSidebar()
{
return sidebar;
}

/**
* Set the value of sidebar.
*
* @param v
* Value to assign to sidebar.
*/
public void setSidebar(String v)
{
this.sidebar = v;
}

/**
* Get the value of sidebar.
*
* @return Value of sidebar.
*/
public String getNocache()
{
return noCache;
}

/**
* Set the value of sidebar.
*
* @param v
* Value to assign to sidebar.
*/
public void setNocache(String v)
{
this.noCache = v;
}

/**
* Get the value of feedData.
*
* @return Value of feedData.
*/
public String getFeedData()
{
return feedData;
}

/**
* Set the value of feedData.
*
* @param v
* Value to assign to feedData.
*/
public void setFeedData(String v)
{
this.feedData = v;
}

public void release()
{
style = null;
title = null;
sidebar = null;
navbar = null;
locbar = null;
parentTitle = null;
parentLink = null;
noCache = null;
feedData = null;
}
}
lsmsilence 2009-12-02
  • 打赏
  • 举报
回复
LayoutTagpublic class LayoutTag extends TagSupport
{
/** log4j logger */
private static Logger log = Logger.getLogger(LayoutTag.class);

/** layout style name */
private String style;

/** title */
private String title;

/** title key (from message dictionary) */
private String titleKey;

/** Navigation bar type, null means none */
private String navbar;

/** Location bar type */
private String locbar;

/** Name of "parent" page */
private String parentTitle;

/** Name of "parent" page key (from message dictionary) */
private String parentTitleKey;

/** Link to "parent" page */
private String parentLink;

/** Contents of side bar */
private String sidebar;

/** Whether to add headers to prevent browsers caching the page */
private String noCache;

/** Syndication feed "autodiscovery" link data */
private String feedData;

public LayoutTag()
{
super();
}

public int doStartTag() throws JspException
{
ServletRequest request = pageContext.getRequest();

// header file
String header = "/layout/header-default.jsp";

// Choose default style unless one is specified
if (style != null)
{
header = "/layout/header-" + style.toLowerCase() + ".jsp";
}

// Sort out location bar
if (locbar == null)
{
locbar = "auto";
}

// These lists will contain titles and links to put in the location
// bar
List parents = new ArrayList();
List parentLinks = new ArrayList();

if (locbar.equalsIgnoreCase("off"))
{
// No location bar
request.setAttribute("dspace.layout.locbar", new Boolean(false));
}
else
{
// We'll always add "DSpace Home" to the a location bar
parents.add(ConfigurationManager.getProperty("dspace.name"));

if (locbar.equalsIgnoreCase("nolink"))
{
parentLinks.add("");
}
else
{
parentLinks.add("/");
}

// Add other relevant components to the location bar
if (locbar.equalsIgnoreCase("link"))
{
// "link" mode - next thing in location bar is taken from
// parameters of tag, with a link
if (parentTitle != null)
{
parents.add(parentTitle);
parentLinks.add(parentLink);
}
else if (parentTitleKey != null)
{
parents.add(LocaleSupport.getLocalizedMessage(pageContext,
parentTitleKey));
parentLinks.add(parentLink);
}

}
else if (locbar.equalsIgnoreCase("commLink"))
{
// "commLink" mode - show all parent communities
Community[] comms = (Community[]) request
.getAttribute("dspace.communities");

if (comms != null)
{
for (int i = 0; i < comms.length; i++)
{
parents.add(comms[i].getMetadata("name"));
parentLinks.add("/handle/" + comms[i].getHandle());
}
}
}
else if (locbar.equalsIgnoreCase("nolink"))
{
// "nolink" mode - next thing in location bar is taken from
// parameters of tag, with no link
if (parentTitle != null)
{
parents.add(parentTitle);
parentLinks.add("");
}
}
else
{
// Grab parents from the URL - these should have been picked up
// by the HandleServlet
Collection col = (Collection) request
.getAttribute("dspace.collection");
Community[] comms = (Community[]) request
.getAttribute("dspace.communities");

if (comms != null)
{
for (int i = 0; i < comms.length; i++)
{
parents.add(comms[i].getMetadata("name"));
parentLinks.add("/handle/" + comms[i].getHandle());
}

if (col != null)
{
parents.add(col.getMetadata("name"));
parentLinks.add("/handle/" + col.getHandle());
}
}
}

request.setAttribute("dspace.layout.locbar", new Boolean(true));
}

request.setAttribute("dspace.layout.parenttitles", parents);
request.setAttribute("dspace.layout.parentlinks", parentLinks);

51,408

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧