SPRINGMVC Series (v) Use the Serlvet native API as a parameter to the target method

Source: Internet
Author: User
Tags locale

What SERVLETAPI types of parameters can be accepted by the handler method of SPRINGMVC

? HttpServletRequest
? HttpServletResponse
? HttpSession
? Java.security.Principal
? Locale
? InputStream
? OutputStream
? Reader
? Writer

Code Combat:

1. Introducing the dependencies required to use the Serlvet native API in Pom.xml

1 <!--development JSP needs to rely on, there are HttpServletRequest,2 HttpServletResponse and other native parameters begin -3     <Dependency>4       <groupId>Org.apache.tomcat</groupId>5       <Artifactid>Jsp-api</Artifactid>6       <version>6.0.53</version>7     </Dependency>8     9     <Dependency>Ten       <groupId>Org.apache.tomcat</groupId> One       <Artifactid>Servlet-api</Artifactid> A       <version>6.0.48</version> -     </Dependency> -     <!--development JSP needs to rely on, there are HttpServletRequest, the HttpServletResponse and other native parameter end -

2. Writing index.jsp

1 <BR/><BR/>2 <P><b>Using the Serlvet native API as a parameter to the target method begin</b></P>3 <ahref= "Servletapitest/testservletapi">Testservletapi</a>4 <P><b>Using the Serlvet native API as a parameter to the target method</b></P>

3. Writing handle

1  Packagecom.study.springmvc.handlers;2 3 Importjava.io.IOException;4 ImportJava.io.Writer;5 6 Importjavax.servlet.http.HttpServletRequest;7 ImportJavax.servlet.http.HttpServletResponse;8 9 ImportOrg.springframework.stereotype.Controller;Ten Importorg.springframework.web.bind.annotation.RequestMapping; One  A@RequestMapping ("/servletapitest") - @Controller -  Public classServletapitest { the  -      Public Static FinalString success= "SUCCESS"; -      -     /** + * The following types can be specifically supported using the Serlvet native API as a parameter of the target method -      *  + * HttpServletRequest A * HttpServletResponse at * HttpSession - * Java.security.Principal - * Locale InputStream - * OutputStream - * Reader - * Writer in      * @throwsIOException -      */ to@RequestMapping ("/testservletapi") +      Public voidTestservletapi (httpservletrequest request, -HttpServletResponse response, Writer out)throwsIOException { theSystem.out.println ("Testservletapi," + Request + "," +response); *Out.write ("Hello Springmvc"); $ //return SUCCESS;Panax Notoginseng     } -}

4. Enter the address http://127.0.0.1:8080/SpringMVC/access to index.jsp click on the second part of the index.jsp written in the hyperlinks to see the effect

SPRINGMVC Series (v) Use the Serlvet native API as a parameter to the target method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.