最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
servlet 绝对路径和相对路径获取代码
时间:2022-06-29 02:39:21 编辑:袖梨 来源:一聚教程网
servlet 绝对路径和相对路径获取代码
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/plain; charset=Shift_JIS");
PrintWriter out = res.getWriter();
res.setHeader("Content-Language", "ja");
Locale locale = new Locale("ja", "");
DateFormat full = DateFormat.getDateTimeInstance(DateFormat.LONG,
DateFormat.LONG,
locale);
out.println("In Japanese:");
try {
FileInputStream fis =
new FileInputStream(req.getRealPath("/HelloWorld.ISO-2022-JP"));
InputStreamReader isr = new InputStreamReader(fis, "ISO-2022-JP");
BufferedReader reader = new BufferedReader(isr);
String line = null;
while ((line = reader.readLine()) != null) {
out.println(line);
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
out.println(full.format(new Date()));
}
}
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
判断来自文件路径信息
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/plain");
PrintWriter out = res.getWriter();
if (req.getPathInfo() != null) {
out.println("The file "" + req.getPathInfo() + """);
out.println("Is stored at "" + req.getPathTranslated() + """);
}
else {
out.println("Path info is null, no file to lookup");
}
}
}
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
相关文章
- 人们熟悉的寄居蟹属于以下哪种分类 神奇海洋11月21日答案 11-21
- 第五人格11.22共研服有什么更新 11月22日共研服更新内容介绍 11-21
- 原神恰斯卡怎么培养 11-21
- 无期迷途四星装束是谁 11-21
- 王者荣耀帝丹高中校服怎么获得 11-21
- 光遇姆明季后续版本怎么玩 11-21