java 前三讲 汇总 9幅图


技术分享

技术分享

技术分享

技术分享

技术分享

web.xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
  5. http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
  6. version="3.1">
  7. <servlet>
  8. <servlet-name>spring</servlet-name>
  9. <servlet-class>
  10. org.springframework.web.servlet.DispatcherServlet
  11. </servlet-class>
  12. <load-on-startup>1</load-on-startup>
  13. </servlet>
  14. <servlet-mapping>
  15. <servlet-name>spring</servlet-name>
  16. <url-pattern>*.do</url-pattern>
  17. </servlet-mapping>
  18. <filter>
  19. <filter-name>encodingFilter</filter-name>
  20. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  21. <init-param>
  22. <param-name>encoding</param-name>
  23. <param-value>UTF-8</param-value>
  24. </init-param>
  25. <init-param>
  26. <param-name>forceEncoding</param-name>
  27. <param-value>true</param-value>
  28. </init-param>
  29. </filter>
  30. <filter-mapping>
  31. <filter-name>encodingFilter</filter-name>
  32. <url-pattern>*.do</url-pattern>
  33. </filter-mapping>
  34. </web-app>
spring-servlet.xml
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
  6. <!-- the application context definition for the springapp DispatcherServlet -->
  7. <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  8. <property name="prefix" value="/WEB-INF/jsp/"></property>
  9. <property name="suffix" value=".jsp"></property>
  10. </bean>
  11. <bean id="urlMapping"
  12. class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
  13. <property name="mappings">
  14. <props>
  15. <prop key="/index.do">IndexAction</prop>
  16. </props>
  17. </property>
  18. </bean>
  19. <bean id="IndexAction" class="com.myweb.IndexAction">
  20. <property name="view">
  21. <value>index</value>
  22. </property>
  23. </bean>
  24. </beans>
IndexAction.java
  1. package com.myweb;
  2. import org.springframework.web.servlet.mvc.Controller;
  3. import org.springframework.web.servlet.ModelAndView;
  4. import javax.servlet.http.HttpServletResponse;
  5. import javax.servlet.http.HttpServletRequest;
  6. public class IndexAction implements Controller {
  7. public String view;
  8. public String getView() {
  9. return view;
  10. }
  11. public void setView(String view) {
  12. this.view = view;
  13. }
  14. @Override
  15. public ModelAndView handleRequest(HttpServletRequest arg0,
  16. HttpServletResponse arg1) throws Exception {
  17. // TODO Auto-generated method stub
  18. ModelAndView mv=new ModelAndView(view);
  19. mv.addObject("hello", "你好");
  20. mv.addObject("myname", "shenyi");
  21. return mv;
  22. }
  23. }
index.jsp
  1. <%
  2. String get_hello = request.getAttribute("hello").toString();
  3. response.getWriter().write(get_hello);
  4. %>
  5. ${hello} my name is ${myname}





郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。