target.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>target.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> </head> <body>
目标资源html页面
</body>
</html>

servlet:

package path;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* web应用中路径问题
* @author Administrator
*
*/
public class PathDemo extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html; charset=utf-8");
//目标资源: target.html
/*
* 思考: 目标资源是给谁使用的。
* 给服务器使用的: / 表示在当前web应用的根目录(webRoot下)
* 给浏览器使用的: / 表示在webapps的根目录下
*/ /*
* 1.转发
* 给服务器使用的
*/
// request.getRequestDispatcher("/target.html").forward(request, response); /*
* 2.请求重定向
* 给浏览器使用的
*/
// response.sendRedirect("/day11/target.html"); /*
* 3.html页面的超连接href
* 给浏览器使用的
*/
// response.getWriter().write("<html><body><a href='/day11/target.html'>超链接</a></body></html>"); /*
* 4.html页面中的form提交地址
*/
response.getWriter().write("<html><body><form action='/day11/target.html'><input type='submit'/></form></body></html>");
} }

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name></display-name> <servlet>
<servlet-name>ResourceDemo</servlet-name>
<servlet-class>resource.ResourceDemo</servlet-class>
</servlet> <servlet-mapping>
<servlet-name>ResourceDemo</servlet-name>
<url-pattern>/ResourceDemo</url-pattern>
</servlet-mapping>
</web-app>

最新文章

  1. C#系列——记一次业务需求:对象的深拷贝
  2. 千呼万唤始出来!—— GG(高仿QQ)终于有移动端了!(技术原理、实现、源码)
  3. Hightcharts设置Y轴最大最小值
  4. jsp&amp;servlet学习笔记
  5. 苹果公司给出的检测 advertisingIdentifier 的方法
  6. FTP主/被动模式的原理
  7. ReactNative 踩坑小计
  8. csuoj 1352: New Sorting Algorithm
  9. iOS 相机手动对焦
  10. Java实现生命周期管理机制
  11. EditText设置可以编辑和不可编辑状态
  12. 在FMX中实现PostMessage的方法
  13. 二维码(QR Code)生成与解析
  14. JSP(基础语法)
  15. bootstrap 响应式导航条模板(含下拉菜单,弹出框)
  16. vue style width a href动态拼接问题 ?
  17. 正则-匹配IP地址
  18. curl安装和使用
  19. 关于 Shell 的相关概念和配置方法,全在这儿了!
  20. flutter key

热门文章

  1. UML图与机房收费系统实例
  2. css的white-space属性导致了空格问题——查看十六进制发现2020变成了c2a0
  3. Linux Centos7 Apache 訪问 You don&amp;#39;t have permission to access / on this server.
  4. EXCEL单元格的获取——多例模式
  5. 2011:Audio Classification (Train/Test) Tasks - MIREX Wiki
  6. 20160225.CCPP体系具体解释(0035天)
  7. 对“使用MyEclipse,写的jsp代码因有汉字而无法保存”问题的解决
  8. [DLX反复覆盖] poj 1084 Square Destroyer
  9. list-style样式不显示问题
  10. 树状数组 LA 4329 亚洲赛北京赛区题