原本想要通过一个jsp页面,显示我电脑文件里面收藏的漫画,(平常漫画都是下载下来看的,不用翻页)可是在编写jsp代码的时候却出现很多问题,反映了我编程的水平的不足
这是我写的index.jsp代码
望高手指教
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="java.io.File"%>
<%
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 'MyJsp.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>
<%
String url=request.getParameter("url");//获取文件路径
if(url==null){
url="E:\\我的漫画";
System.out.print(url);
}
// else{
//url=url.replaceAll("\\\\","\\\\\\\\");//原本以为是路径有错误
// System.out.print(url);
// }
File file=new File(url);
// 首页能够显示正常
File[] files = file.listFiles();
for (File f : files) {
if (f.isDirectory()) {
System.out.println("----------------" + f.getAbsolutePath()
+ "-------------");
%>
<a href="index.jsp?url=<%= f.getAbsolutePath() %>"><%=f.getName() %></a>
<p>
<%
} else { // 如果是文件 就显示图片文件
%>
<img src="<%=f.getAbsolutePath() %>"/>
<%
}
}
%>
</body>
</html>
这是我写的index.jsp代码
望高手指教
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="java.io.File"%>
<%
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 'MyJsp.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>
<%
String url=request.getParameter("url");//获取文件路径
if(url==null){
url="E:\\我的漫画";
System.out.print(url);
}
// else{
//url=url.replaceAll("\\\\","\\\\\\\\");//原本以为是路径有错误
// System.out.print(url);
// }
File file=new File(url);
// 首页能够显示正常
File[] files = file.listFiles();
for (File f : files) {
if (f.isDirectory()) {
System.out.println("----------------" + f.getAbsolutePath()
+ "-------------");
%>
<a href="index.jsp?url=<%= f.getAbsolutePath() %>"><%=f.getName() %></a>
<p>
<%
} else { // 如果是文件 就显示图片文件
%>
<img src="<%=f.getAbsolutePath() %>"/>
<%
}
}
%>
</body>
</html>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货