首页 > PHP资讯 > HTML5培训技术 > 第五课-JSP和Servlet之间的跳转

第五课-JSP和Servlet之间的跳转

HTML5培训技术

 

 

第五课 - JSP和Servlet之间的跳转

一丨Jsp 跳转到 Servlet

1,使用forward()

2,使用sendReDirect()

3,两者的区别请见博文(Jsp之Forward & SendReDirect 的区别)

二丨Servlet 跳转到 JSP

this(HttpServlet)

.getServletConfig() 获取Servlet的容器配置对象

.getServletContext() 获取Servlet的上下文对象

.getRequestDispatcher(/ServletToJsp. ; charset=UTF-8 pageEncoding=UTF-8%> <% request.setCharacterEncoding(UTF-8); %><% response.sendRedirect(/StudyING/ServletToJsp); %> <%-- --%>

 

ServletToJSP.java

 

package com.qsuron.study;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;@WebServlet(/ServletToJsp)public class ServletToJsp extends HttpServlet {	@Override	protected void doGet(HttpServletRequest req, HttpServletResponse resp)			throws ServletException, IOException {		System.out.println(This is Servlet,Now fowward to JSP);		this.getServletConfig().getServletContext()		.getRequestDispatcher(/ServletToJsp.jsp).forward(req,resp);	}	}

 

 

ServletToJSP.jsp

 

<%@ page language=java pageEncoding=UTF-8 contentType=text/html; charset=UTF-8 %>    <% request.setCharacterEncoding(UTF-8); %>

This Is A Jsp File Which Used To Forward From Servlet



 

 

 

转载请注明出处:blog.csdn.net/qsuron 小树博客 博主小树 (qsuron)

 

 


HTML5培训技术

本文由欣才IT学院整理发布,未经许可,禁止转载。
支持43不支持0