zoukankan      html  css  js  c++  java
  • nutz_web应用中主页跳转到登录页面的方式

    一、前言

        web应用开发时,地址栏输入ip+port+appName,通常可以跳转到登录页面。以下便介绍我所知道并且验证过的三种跳转方式。

    二、准备工作

        需要使用到两个url的处理分别如下:

        @At("/index")
        @Ok("redirect:/toLogin")
        @Filters//表示该url不被过滤(使用一个空的过滤器)
        public void init(){
            
        }
        
        @At("/toLogin")
        @Ok("")//此处配置登录页面的地址路径
        @Filters
        public void toLogin(){
            
        }

    三、三种跳转登录页面的方式

    1、配置<welcome-file-list>为存在的index.jsp页面路径

        <welcome-file-list>配置如下:

        <welcome-file-list>
           <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>

        此处index.jsp在WebContent目录下。并在index.jsp中添加如下代码:

    <%
        request.sendRedirect("/index")
    %>

      2、配置<welcome-file-list>为一个url。如下所示:

        <welcome-file-list>
           <welcome-file>index.html</welcome-file>
        </welcome-file-list>

        此处:index.html为一个url路径。此时需要在WebContent目录下,添加一个空的index.html文件。 这样的话,输入ip+port+appName时,就会默认访问/index.html这个路径。从而实现向登录页面的跳转。

        注意:若使用struts2,则ur名字可能为index.action。此时需在WebContent目录下新增:index.action空文件。 文件名与配置的url一致。

    3、使用UriWriter实现不配置<welcome-file-list>以及不新增index.jsp或index.html等文件时,跳转到登录页面的功能。【不推荐使用,因为这样会使简单的问题复杂化。】

        步骤1:引入urlWriter的jar包

        步骤2:在web.xml中添加如下配置:

      <filter>
        <filter-name>UrlRewriteFilter</filter-name>
        <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
      </filter>
      <filter-mapping>
        <filter-name>UrlRewriteFilter</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>

        步骤3:在WEB-INF下新增名为:urlrewrite.xml的文件(注意:文件名只能为urlrewrite.xml),内容如下:

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN"
            "http://tuckey.org/res/dtds/urlrewrite3.2.dtd">
    <urlrewrite>
        <rule>
            <from>^/$</from>
            <to>/index</to>
        </rule>
      
    </urlrewrite>

        即:当路径为"/"时,会默认以forward的形式转化为执行"/index"。从而实现到/index的访问,进而实现到登录页面的跳转。

    四、参考资料:

    1、通过配置<welcome-file-list>实现主页跳转:http://blog.csdn.net/zzq900503/article/details/44460963

    2、urlWriter使用:http://blog.csdn.net/lgg201/article/details/5329364

                             http://www.osblog.net/blog/507.html

    ==================================================================================================

    以上仅为我个人初学nutz的一点小小的使用经验,如有不正确和不恰当的地方,请大家多多指出,共同进步!

    如有转载,请指明出处。谢谢!

  • 相关阅读:
    React.js学习笔记之事件系统
    彻底解决Webpack打包慢的问题:npm run build:dll
    gulp详细入门教程
    cmd、node、npm 常用命令
    ant design中ES6写法个人总结
    自定义浏览器滚动条的样式,打造属于你的滚动条风格
    js相关知识
    day31-python阶段性复习五
    day30-python阶段性复习四
    day29-python阶段性复习三
  • 原文地址:https://www.cnblogs.com/lindsay-chh/p/4622226.html
Copyright © 2011-2022 走看看