【路径/.../...】总结【Me】

来源:互联网 发布:unity3d教程视频哪个好 编辑:程序博客网 时间:2024/06/15 18:08

1、在Html的img src中要这样写

<!DOCTYPE html>
<html>
  <head>
    <title>register.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>
    <form action="">
  用户名:<input type="text" name="username"/><br/>
  密码:<input type="password" name="password"><br/>
  验证码:<input type="text" name="checkcode"/> <img src="/myday06/servlet/ResponseDemo4"><br/>
  <input type="submit" value="注册"/><br/>
  </form>
  </body>
</html>

2、在JSP的a href中要这样写

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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 'index.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>
    <a href="/myday06/register.html">点点</a>
  </body>
</html>

3、在servlet的sendRedirect中要这样写

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.sendRedirect("/myday06/servlet/ResponseDemo6");     
    
}

4、在servlet的getRequestDispatcher中这样写

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {  
this.getServletContext().getRequestDispatcher("/servlet/ResponseDemo6").forward(request, response);     
}

0 0
原创粉丝点击