zoukankan      html  css  js  c++  java
  • 地址标记,SpringMVC转发与调用相关知识存档

    1.mytest_mavenprj1中,index的

          <a href="login/login.html">点击登录</a> 

      与   <a href="/login/login.html">点击登录</a> 

      区别明显,后者访问时丢失项目名称目录

    摘抄:[路径与servlet参数传递]

      "/"表示的也是绝对路径.但是这里的"/"表示的绝对路径是http://localhost:8080 不包括后面的工程名.

      相对路径表示的是Parameter.jsp所在的目录下的ServletTest这个映射.其实就是web.xml里面配置的那个url-pattern

    2.  DispatcherServlet相关知识

      2.1 DispatcherServlet测试1:@RequestMapping("/mytest"),@RequestMapping("/login")

        ControllerClass添加@RequestMapping("/mytest") + 方法添加@RequestMapping("/login")之后

        在mytest/index.jsp中调用action="login.do"

        调用成功,console输出信息:

            Matching patterns for request [/mytest/login.do] are [/mytest/login.*]

        跳转信息(404)(在controller中return null的情况下):

            message /mavenprj1/mytest/login.jsp

            默认跳转地址为以上   

        地址栏显示信息(重要):

            http://localhost:8080/mavenprj1/mytest/login.do

            即只显示提交时传递的信息,返回的地址信息在地址栏中得到了隐藏

      2.2 DispatcherServlet测试2:controller参数(String username, String password, HttpServletRequest request)

        ControllerClass的方法添加return username;

        在mytest/index.jsp中调用action="login.do"

        调用成功,response返回信息:message /mavenprj1/AA/asfdasdf.jsp

          默认跳转地址为return信息+jsp

        说明:其中添加".jsp"是在spring-mvc.xml中的设置

      <!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
      <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/AA/" p:suffix=".jsp" />

       2.3 DispatcherServlet测试1补充:

        ControllerClass添加@RequestMapping("/mytest") + 方法添加@RequestMapping("/login")之后

        在mytest文件夹下新建jsp页面,测试转发同样达到效果。

        结论:@RequestMapping("/mytest")表示此路径(包)下的action请求都经过此ControllerClass处理;

    3.关于ModelAndView

      3.1测试mav.setViewName("listjob2") 并且return mav

        结论,测试效果为返回的页面地址信息有效;

      

  • 相关阅读:
    oracle 插入timestamp
    ?--Porg.springframework.beans.MethodInvocationException: Property 'username' threw exception; nested exception is java.lang.NullPointerException
    把工程部署在tomcat的root路径下
    修改tomcat 启动45秒
    struts2 ,web.xml中配置为/*.action,运行报错Invalid <url-pattern> /*.action in filter mapp
    解决Tomcat 7遇到StackOverflowError的异常
    eclipse 安装svn插件
    WP8_ListBox的用法
    WP8_检测列表是否滑动
    WP8_访问ListBox中的Item项中的某个元素
  • 原文地址:https://www.cnblogs.com/otio/p/4174370.html
Copyright © 2011-2022 走看看