sturts2的路径

interceptors 总共35个拦截器,底层默认执行20个拦截器

后台: / 当前应用的根路径

前台: 前/ 相对路径

解析完毕后的效果

   后台路径:[http://localhost/02-path](http://localhost/02-path)/

   前台路径:http://localhost/02-path/test/login[/02-path/test/login中/代表http://localhost]

如果对比成功,则跳转成功

4种方法:

1:缺省项目名

2:/获取前台路径

3:通过el表达式获取项目名称

4:通过basePath 获取路径

 <!--前台:缺省/ 是相对路径写法 参照的是服务器的根路径  -->

  <!--前台提交路径发生变化 namespace/name  -->

   <!--  <form action="test/Login" method="post">

    用户名:<input type="text" name="username">

    密&nbsp;码:<input type="password" name="password">

    <input type="submit" value="提交">

    </form> 

    <!-- 前台/写法 :代表服务器的根路径 [http://localhost/--struts.xml](http://localhost/--struts.xml)对一下

    跳转路径:404 ?/test/Login 缺少项目名称

    现在路径:http:localhost/02-psth/test/login 
                  :http:localhost/项目名/namespace/action的name
<package name="xxx" namespace="/test" extends="struts-default">
<action name="login" class="com.lanou.entity.LoginAction">
    -->
<!--  <form action="/02-path/test/Login" method="post">

用户名:<input type="text" name="username">

密&nbsp;码:<input type="password" name="password">

<input type="submit" value="提交">

</form> -->

<!--问题:可以跳转 但是每次写项目名称,能不能自动获取项目名称

解决:EL表达式

  -->

el 表达式

   <%--   <form action="${pageContext.request.contextPath}/test/Login" method="post">

    用户名:<input type="text" name="username">

    密&nbsp;码:<input type="password" name="password">

    <input type="submit" value="提交">

    </form> --%>


<!--

问题:太麻烦,单词太长,记不住   解决:basePath:

-->
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

  <form action="<%=basePath%>test/Login" method="post">

用户名:<input type="text" name="username">

密&nbsp;码:<input type="password" name="password">

<input type="submit" value="提交">

</form>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,868评论 18 139
  • 前言 这里筑梦师,是一名正在努力学习的iOS开发工程师,目前致力于全栈方向的学习,希望可以和大家一起交流技术,共同...
    筑梦师Winston阅读 26,080评论 80 514
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,025评论 25 708
  • 如果,哪天,我不能像现在这样静静的坐着 到那时安静对于我来说是一种奢侈, 若真的到了这种状态, 我很难察觉到身上不...
    夜梭静省阅读 346评论 0 0
  • 幽黄的街灯, 瞅着飞驰的车轮, 遮不住奔舞的灰尘。 零星虫儿的颤吻, 似娇万千依存, 却扇不尽这冬寒冷。
    月光碉堡阅读 268评论 0 1