国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
JSP中的redirect和forward

下面是別人總結的很全面

 

http://www.blogjava.net/yzzh9/archive/2009/06/09/280908.html

 

 

 

http://www.diybl.com/course/4_webprogram/jsp/jsp_js/200863/121115.html#

 

 

 

 

下面是自己總結的:代碼可以運行的??梢赃\行下看看,加深理解。

 

1、登錄jsp頁面

 

<%@ page language="java" contentType="text/html"
    pageEncoding="utf-8"%>
<html>
<head>
<title>this first jsp and Servlet</title>
</head>
<body>
 <form action="tpath" method="post">
名字:<input type="text" name="uname">
密碼:<input type="text" name="password"><br>
     <input type="submit" value="提交">
     </form>
</body>
</html>

 

 

2、servlet類的寫法

 

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TestTZ extends HttpServlet{

 @Override
 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
   throws ServletException, IOException {
  // TODO Auto-generated method stub
  this.doPost(req, resp);
 }

 @Override
 protected void doPost(HttpServletRequest req, HttpServletResponse resp)
   throws ServletException, IOException {
      String path2="/testPath.jsp";
      String path3="testPath.jsp";
       String uname=req.getParameter("uname");
       String password=req.getParameter("password");
       
       req.setAttribute("k", uname);
       req.setAttribute("v", password);
       
        //   this.getServletConfig().getServletContext().getRequestDispatcher(path2).forward(req, resp);
       
        // req.getRequestDispatcher(path3).forward(req, resp);
     // 上面兩個forward方法都可以,跳轉到另外一個頁面(他們是服務器端跳轉)。IE里面的地址看不出跳轉到那個jsp頁面。
     //但是上面的兩個跳轉的具體區(qū)別,還有點不太清楚。
     //============================================================
       
       
       //sendRedirect它是客戶端跳轉,可以在IE里面看到,跳轉到那個jsp頁面。
       //但是它不能通過request.getAttribute("變量");得到值。
       resp.sendRedirect(path3);
 }
}

 

3、接受值的jsp的寫法

 

<%@ page language="java" contentType="text/html"
    pageEncoding="utf-8"%>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
結果是:<br>
<%=request.getAttribute("k") %><br>
<%=request.getAttribute("v") %>
</body>
</html>

 

4、servlet的配置文件web.xml的寫法

 

       <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
 xmlns=" 
 xmlns:xsi="
 
 xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee 
   <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
  <servlet>
  <servlet-name>jack3</servlet-name>
  <servlet-class>org.tiaozhuan.com.TestTZ</servlet-class>
  </servlet>
  
  <servlet-mapping>
  <servlet-name>jack3</servlet-name>
  <url-pattern>/tpath</url-pattern>
  </servlet-mapping>
  
 </web-app>

打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
servlet、jsp跳轉(傳值)總結及URL傳參數
javax.servlet.http.HttpServlet doGet和doPost方法的簡單介紹
Servlet 編寫三種方式
jsp+servlet實現注冊登錄,不用數據庫
JSP復習筆記
Servlet響應之頁面形式
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯系客服!

聯系客服