`

How to forward requests from Servlet to JSP

    博客分类:
  • java
阅读更多

servletToJsp.java

<!----> <!---->
import  java.io.IOException;
import  javax.servlet.*;
import  javax.servlet.http.*;
public class  servletToJsp  extends  HttpServlet  {

   public  void  doGet ( HttpServletRequest request, HttpServletResponse response ){
     request.setAttribute ( "servletName" "servletToJsp" ) ;

     try  {
       getServletConfig () .getServletContext () .getRequestDispatcher (
         "/JSP/Demo.hello.jsp" ) .forward ( request,response ) ;

     catch  ( ServletException e ) {
       // TODO Auto-generated catch block
       e.printStackTrace () ;
     catch  ( IOException e ) {
       // TODO Auto-generated catch block
       e.printStackTrace () ;
     }
   }

}
<!----> <!---->

hello.jsp which display the servlet name passed by servletToJsp servlet.

<!---->

<html>
<body bgcolor= "white" >
<h1> I have been invoked by 
<% 
out.print ( request.getAttribute ( "servletName" ) .toString ()) ;
%>
Servlet
</body>
</html>

分享到:
评论

相关推荐

    servlet2.4doc

    Forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server. -------------------------------------------------------------------------------- G ...

    Python.Requests.Essentials.1784395412

    Learn how to integrate your applications seamlessly with web services using Python Requests About This Book A fast-paced guide that demonstrates the use of Python Requests with the help of examples ...

    How.to.Use.Objects.Code.and.Concepts.0321995546

    He explains the roles of individual objects in a complete application, how they react to events and fulfill service requests, and how to transform excellent designs into excellent code. Using ...

    Operating_Systems_From_0_to_1.pdf

    You’ve probably asked yourself at least once how an operating system is written from the ground up. You might even have years of programming experience under your belt,yet your understanding of ...

    import reimport requestsfrom bs4 import BeautifulSoupimport t

    import requests from bs4 import BeautifulSoup import time from xlwt import * poems = [] # 将故事变成了一个全局变量。 def getHtml(page): ''' 获取网页数据 :param page: 页数 :return: 网页html数据...

    网站登录页面代码实例(JSP+Servlet+JavaBean)

    登陆实例(JSP+Servlet+JavaBean) 部分代码如下,下载看全部代码: ; charset=UTF-8"&gt; 登陆 &lt;center&gt;&lt;br&gt; &lt;br&gt; &lt;p&gt;&lt;form action="()%&gt;/CheckServlet" method="post"&gt; &lt;td height="20" colspan="2"&gt;&lt;span...

    Python Requests Essentials(PACKT,2015)

    You will be shown how to mock HTTP Requests using HTTPretty, and will learn to interact with social media using Requests. This book will help you to grasp the art of web scraping with the ...

    Building Blockchain Projects -Packt Publishing((2017).pdf )

    Chapter 7, Building a Betting App, explains how to use Oraclize to make HTTP requests from Ethereum smart contracts to access data from World Wide Web. We will also learn how to access files stored in...

    Java_for_the_Web_with_Servlets

    - **How a Servlet Works**: When a request is sent to a servlet, the servlet container creates a new instance of the servlet if one does not already exist. The `init()` method initializes the servlet, ...

    Android代码-Android应用程序开发例子

    Developing-Android-Apps-course ...Lesson 1 - Creating Project Sunshine - Learn how to create and run a simple ...- Learn about threading and how to make requests without slowing down your app - Learn how t

    Python Requests Essentials

    You will be shown how to mock HTTP Requests using HTTPretty, and will learn to interact with social media using Requests. This book will help you to grasp the art of web scraping with the ...

    Implementing OpenShift

    A Platform-as-a-Service cloud aims to fulfill this need, allowing developers to work more efficiently as well as allowing DevOps teams to spend less time fulfilling requests for these environments....

    Building Blockchain Projects_Develop Real-Packt Publishing(2017)

    Chapter 7, Building a Betting App, explains how to use Oraclize to make HTTP requests from Ethereum smart contracts to access data from World Wide Web. We will also learn how to access files stored in...

    Python库 | requests_from_file-2.2.tar.gz

    《Python库requests_from_file-2.2:高效网络请求管理》 在Python的世界里,进行HTTP请求是一项常见的任务,无论是获取网页数据、提交表单,还是进行API交互,都离不开这个功能。`requests_from_file-2.2.tar.gz`...

    python requests模块及依赖包.zip

    from requests.packages.urllib3.util.retry import Retry retries = Retry(total=3, backoff_factor=0.1, status_forcelist=[500, 502, 503, 504]) adapter = HTTPAdapter(max_retries=retries) session.mount('...

    Introduction.To.Algorithms,.Second.Edition

    Preface This book provides a comprehensive introduction to the modern study of computer algorithms. It presents many algorithms and covers them in considerable depth, yet ...Despite myriad requests from

    python-requests离线包

    本离线包“python-requests”正是为了解决在无网络环境下也能使用这个库的需求。 首先,我们来详细解释一下压缩包中的各个文件: 1. `python-3.7.4-amd64.exe`: 这是Python 3.7.4的安装程序,适用于AMD64架构的...

Global site tag (gtag.js) - Google Analytics