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