jsp页面加入头部以及底部,设置背景

jsp页面加入头部以及底部,设置背景

注意事项:

头部和底部文件编码问题;

用include将头部文件以及底部文件包含进来<%@ includefile="xx.jsp"%>

设置背景图片时路径问题

头部文件:head.jsp

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

    pageEncoding="UTF-8"%>

<tablestyle="height:50px;width:100%;background-color:#cceeff;">

<trstyle="height:45px;">

 <tdstyle="align:center;">首页</td>

 <tdstyle="">招聘信息</td>

 <tdstyle="">公告</td>

 <tdstyle="">联系我们</td>

 <tdstyle="">企业产品</td>

</tr>

</table>

底部文件:down.jsp

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

    pageEncoding="UTF-8"%>

<div style="background-color:#ccddff;">

 联系我们:000000-5555555-55555</br>

xxxxxxxxxx-科技

</div>

将以上两个页面合并,同时设置背景图片

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

    pageEncoding="UTF-8"%>

 <%String path = request.getContextPath();

String basePath =request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>   

<!DOCTYPEhtml PUBLIC "-//W3C//DTDHTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<metahttp-equiv="Content-Type"content="text/html; charset=UTF-8">

<title>Insert title here</title>

</head>

<style>

body{

background-image:url(<%=basePath%>image/bg.jpg);

}

</style>

<body>

<%--加载页头和页尾--%>

<%@ include file="head.jsp"%>

<divstyle="height:500px;">内容</div>

<%@ include file="down.jsp"%>

</body>

</html>

 

猜你喜欢

转载自blog.csdn.net/qi95719/article/details/53366129