五月综合缴情婷婷六月,色94色欧美sute亚洲线路二,日韩制服国产精品一区,色噜噜一区二区三区,香港三级午夜理伦三级三

您現(xiàn)在的位置: 365建站網(wǎng) > 365文章 > JSP利用URL重寫(xiě)傳遞參數(shù)示例

JSP利用URL重寫(xiě)傳遞參數(shù)示例

文章來(lái)源:365jz.com     點(diǎn)擊數(shù):1016    更新時(shí)間:2009-10-14 10:50   參與評(píng)論

在servlet頁(yè)中重定向到index.jsp頁(yè),但重寫(xiě)index.jsp頁(yè)的URL傳遞兩個(gè)參數(shù)給index頁(yè)


1.Servlet頁(yè):


/**
 *
 * @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 description";
    }

}



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"
   "http://www.w3.org/TR/html4/loose.dtd">

<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

如對(duì)本文有疑問(wèn),請(qǐng)?zhí)峤坏浇涣髡搲瑥V大熱心網(wǎng)友會(huì)為你解答?。?點(diǎn)擊進(jìn)入論壇

發(fā)表評(píng)論 (1016人查看,0條評(píng)論)
請(qǐng)自覺(jué)遵守互聯(lián)網(wǎng)相關(guān)的政策法規(guī),嚴(yán)禁發(fā)布色情、暴力、反動(dòng)的言論。
昵稱(chēng):
最新評(píng)論
------分隔線----------------------------

其它欄目

· 建站教程
· 365學(xué)習(xí)

業(yè)務(wù)咨詢

· 技術(shù)支持
· 服務(wù)時(shí)間:9:00-18:00
365建站網(wǎng)二維碼

Powered by 365建站網(wǎng) RSS地圖 HTML地圖

copyright © 2013-2024 版權(quán)所有 鄂ICP備17013400號(hào)