写一个jsp例子,如何让页面背景图片只占据页面上半部分。
时间: 2024-03-10 10:49:59 浏览: 16
以下是一个JSP示例,可以让页面背景图片只占据页面上半部分:
```jsp
<!DOCTYPE html>
<html>
<head>
<title>Background Image on Top Half of Page</title>
<style type="text/css">
body {
background-image: url('your_background_image_url');
background-repeat: no-repeat;
background-position: center top;
background-size: 100% 50%;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<p>This is a sample JSP page with a background image on the top half of the page.</p>
</body>
</html>
```
在上面的示例中,我们使用了`background-size`属性来控制背景图片的大小。我们将它设置为`100% 50%`,表示背景图片的宽度应该铺满整个页面,而高度只占据页面的上半部分。这样一来,我们就可以让背景图片只在页面的上半部分显示出来了。
相关问题
写一个jsp例子,让页面的背景图片向下移动两行
以下是一个JSP示例,可以让页面的背景图片向下移动两行:
```jsp
<!DOCTYPE html>
<html>
<head>
<title>Move Background Image Down</title>
<style type="text/css">
body {
background-image: url('your_background_image_url');
background-repeat: repeat-y;
background-position: center top;
animation: moveBackground 5s linear infinite;
}
@keyframes moveBackground {
from {
background-position: center top;
}
to {
background-position: center calc(100% + 2em);
}
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<p>This is a sample JSP page with a moving background image.</p>
</body>
</html>
```
在上面的示例中,我们使用CSS3的动画特性来实现背景图片向下移动的效果。我们定义了一个名为`moveBackground`的关键帧动画,它将背景图片的位置从顶部向下移动两行。然后,我们将这个动画应用到了`body`元素上,使得整个页面的背景图片都可以动态地向下移动。
再写一个在JSP页面上输出服务器端的IP地址的例子
在JSP页面上输出服务器端的IP地址可以使用Java的内置对象InetAddress来获取,以下是一个示例代码:
```jsp
<%@ page language="java" %>
<%@ page import="java.net.InetAddress" %>
<!DOCTYPE html>
<html>
<head>
<title>获取服务器IP地址</title>
</head>
<body>
<h1>服务器IP地址是:<%= InetAddress.getLocalHost().getHostAddress() %></h1>
</body>
</html>
```
在该示例中,我们使用了Java的内置对象InetAddress的getLocalHost()方法来获取本地主机的IP地址,并使用getHostAddress()方法将其转换成字符串输出到JSP页面上。