时间:2021-05-02
本文讲解了在servlet页中重定向到index.jsp页,但重写index.jsp页的URL传递两个参数给index页。
1.Servlet页中的内容:
/**** @comefrom biye5u.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();}}
@Overridepublic void init(ServletConfig config)throws ServletException{super.init(config);}
@Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {processRequest(request, response);}
@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {processRequest(request, response);}
@Overridepublic String getServletInfo() {return "Short description";}
}
2.index.jsp中的内容:
<%-- Document : indexCreated on : 2009-10-13, 12:59:28Author : 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>翔宇亭IT乐园</title></head><body><%String name = request.getParameter("name");String a = request.getParameter("sid");out.print(a + "<br>" + name);%></body></html>
3.输出结果:
5748
hell
本文源自:翔宇亭——IT乐园(http://www.biye5u.com),转载请保留此信息!声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
1URL路径参数在定义路由URL时,使用正则表达式提取参数的方法从URL中获取请求参数,Django会将提取的参数直接传递到视图的传入参数中。未命名参数按顺序传
javaurl中如何传递数组,springMVC框架controller类如何接收数组参数?下面介绍一下URL中传递数组参数方法:?1dd.do?titles[
1.获取URL参数GET请求参数通过URL传递URL参数可以通过DefaultQuery()或Query()方法获取DefaultQuery()若参数不存在,返
js获取url传递参数,js获取url?号后面的参数的方法:functionGetRequest(){varurl=location.search;//获取
微信小程序navigator跳转url传递参数使用方法说明(1)传值:在navigator的属性url后拼接?id(参数名字)=要传递的值(如果多个参数