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

首頁 > 編程 > JSP > 正文

JSP中利用URL重寫傳遞參數的方法

2024-09-05 00:08:44
字體:
來源:轉載
供稿:網友

本文講解了在servlet頁中重定向到index.jsp頁,但重寫index.jsp頁的URL傳遞兩個參數給index頁。

1.Servlet頁中的內容:

/**
*
* @comefrom vevb.com

*/

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>武林網CUOXIN</title>
</head>
<body>
<%
String name = request.getParameter("name");
String a = request.getParameter("sid");
out.print(a + "<br>" + name);
%>
</body>
</html>

3.輸出結果:

5748

hell

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 健康| 大洼县| 古田县| 铅山县| 鲁山县| 延庆县| 韶山市| 咸宁市| 青神县| 西安市| 浦北县| 南岸区| 井冈山市| 龙江县| 扬州市| 拉孜县| 乌拉特后旗| 剑河县| 张家港市| 巧家县| 齐齐哈尔市| 庆城县| 济源市| 西充县| 翁源县| 绥德县| 平昌县| 涟源市| 资阳市| 界首市| 山东省| 内丘县| 大关县| 绥滨县| 石屏县| 康乐县| 南木林县| 仁布县| 仁寿县| 富民县| 宣汉县|