国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

JSP利用URL重寫傳遞參數示例

2019-11-17 04:10:09
字體:
來源:轉載
供稿:網友

在servlet頁中重定向到index.jsp頁,但重寫index.jsp頁的URL傳遞兩個參數給index頁

1.Servlet頁:


/**
 *
 * @author lucifer
 */


package MyServlet;

import java.io.IOException;
import java.io.PRintWriter;
import javax.servlet.*;
import javax.servlet.http.*;


public class URLRewritingServlet extends HttpServlet {
  
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String urI = response.encodeRedirectURL("http://localhost:8084/LearnServlet/index.jsp?sid=5748&name=hell");
        response.sendRedirect( urI );

        try {
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet URLRewritingServlet</title>"); 
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet URLRewritingServlet at " + request.getContextPath () + "</h1>");
            out.println("</body>");
            out.println("</html>");
        } finally {
            out.close();
        }
    }

    @Override
    public void init(ServletConfig config)throws ServletException{
         super.init(config);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    public String getServletInfo() {
        return "Short descr    }

}

 

 

 

2.index.jsp:

<%--
    Document   : index
    Created on : 2009-10-13, 12:59:28
    Author     : lucifer
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
         <%
               String name = request.getParameter("name");
               String a = request.getParameter("sid");
               out.print(a + "<br>" + name);
         %>
    </body>
</html>

 


3.輸出:

5748

hell


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 遂川县| 孟连| 霸州市| 芮城县| 镶黄旗| 阜宁县| 通道| 鄂托克前旗| 泰兴市| 屏山县| 梁山县| 九江县| 忻城县| 安国市| 客服| 汉中市| 普宁市| 桃江县| 海林市| 台东县| 镇巴县| 巫溪县| 兴化市| 夏津县| 三都| 阿拉善盟| 轮台县| 阿巴嘎旗| 克山县| 永善县| 玉树县| 屏东市| 新兴县| 新巴尔虎左旗| 准格尔旗| 旬阳县| 乌兰浩特市| 溧水县| 郸城县| 泸西县| 额尔古纳市|