nutz_web应用中主页跳转到登陆页面的方式

1、前言html

    web应用开发时,地址栏输入ip+port+appName,一般能够跳转到登陆页面。如下便介绍我所知道而且验证过的三种跳转方式。web

2、准备工做app

    须要使用到两个url的处理分别以下:jsp

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

 

3、三种跳转登陆页面的方式url

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

    <welcome-file-list>配置以下:.net

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

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

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

  二、配置<welcome-file-list>为一个url。以下所示:xml

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

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

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

三、使用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的访问,进而实现到登陆页面的跳转。

4、参考资料:

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

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

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

 

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

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

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

相关文章
相关标签/搜索