谁能给我编写一个简单jsp网页,页面插入一张图片,用相对路径来实现。图片放在WebRoot的img文件夹下。。。

如题所述

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'ComplainUpdateList.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<img src="WebRoot/img/image003.jpg" alt="">
</body>
</html>
改一下文件名就可以了 注意这个JSP必须和webroot同一个目录下边 因为你要的是相对路径
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-02-24
直接在myeclipse下新建一个jsp页面,然后在body里插入<img src="img/...">本回答被网友采纳
相似回答