如何将浏览器中的视图的URL映射到一个特定的名称? [英] How to map the url's of view's in browser to one specific name?

查看:105
本文介绍了如何将浏览器中的视图的URL映射到一个特定的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我的问题是,

我希望当我浏览我的应用程序而不是将URL作为 http:// localhost:8080 / merchant / 我只想显示:// localhost。



像我在浏览应用程序的其他视图时一样获取像 http:// localhost:8080 / merchant / register / list 这样的URL现在我也不希望它显示应用控制器和操作名称,而是希望它显示一个单词可能是列表或其他我想要的东西。



我经历了URLMapping的概念,但是我得到了什么可以做的事情。我知道我应该学习理解和然后询问是否有任何疑问,但我没有太多时间。所以请任何人告诉我究竟需要做什么。

高级谢谢,

解决方案

实际上,如果您在网址中没有端口,则会将端口80设为默认值。通常在这个端口上运行apache http服务。



有两种不同的方式可以在tomcat服务器上运行grails应用程序。




  • 更改tomcat服务器的端口(启动grails时使用Dserver.port参数)



      grails -Dserver.port = 80 run-app 





    • 或者使用apache http服务器作为您的tomcat服务器的代理。



      • http://www.unidata.ucar.edu/projects/THREDDS/tech/tds4.1/reference/TomcatBehindProxyServer.html






        编辑:



        第二件事是用url的。如果我的问题正确,您希望列表视图成为您的默认视图。
        为了达到这个目的,使用下面的URL映射(虽然没有测试):

          static mappings = {
        / $ controller{
        controller =controller
        action =list
        }
        }
        编辑2:



        你只想看看而不是控制器名称。


        • 这只适用于一个控制器。否则grails怎么知道哪个控制器要使用哪个动作。

        • 你可以定义你的动作,这些动作在你的家庭控制器的url中不需要控制器名称就可以访问。


          1. 设置主控制器

          2. 映射





         / $ action
        {
        controller =yourController
        action =action
        }


        请注意,通过这种方式,其他控制器上的所有索引操作都可以。 /控制器将无法正常工作,因为它期望您在家庭控制器中使用名称控制器。




        编辑3:
        您还可以为每个您想要在url中不带控制器名称的操作定义url映射。这种方式的行动不在你的家庭控制器。



        ex


         / myAction
        {
        controller =yourController
        action =myAction
        }



        M new to grails n now my problem is,

        I want when i browse my application instead of getting URL as http://localhost:8080/merchant/ i want to display only ://localhost.

        Like wise when i browse other views of my application i get URL like http://localhost:8080/merchant/register/list now also i don want it to display app controller and action names there instead i want it to display a single word may be list or something else which i want.

        I gone through URLMapping concepts but i din get what exactly to do..I know i should study understand and then ask if any doubt but i don have much time..So please can any one tell me what exactly need to do.

        Advance thanks,

        解决方案

        actually if you don't have a port in the url it takes the port 80 as default. apache http servers are running on this port normally.

        there are two different ways to achieve this for a grails application running on a tomcat server.

        • change the port of the tomcat server (use the Dserver.port parameter when you start grails)

        grails -Dserver.port=80 run-app
        

        • Or use a apache http server as proxy for your tomcat server.

        http://www.unidata.ucar.edu/projects/THREDDS/tech/tds4.1/reference/TomcatBehindProxyServer.html


        EDIT:

        For the second thing with url's. If I get your question right, you want the list view as your default view. To achieve this, use the following URL Mapping (did not test it though):

        static mappings = {
            "/$controller" {
               controller = "controller"
               action = "list"
            }
        }
        


        EDIT 2:

        You only want to see the action and not the controller name.

        • this is only possible for one controller. otherwise how would grails know which action of which controller to use.

        • you can define your actions which should be accessible without the controller name in the url in your home controller.

          1. make a home controller

          2. set the following mapping

        "/$action"
         {
            controller = "yourController"
            action = "action"
         }
        

        please be aware this way all index actions on other controllers ex. /controller will not work right, as it expects you have an action with the name controller in your home controller.


        EDIT 3: You can also define an url mapping for every action you want to be accessible without controller name in the url. this way the action has not to be in your home controller.

        ex

        "/myAction"
         {
            controller = "yourController"
            action = "myAction"
         }
        

        这篇关于如何将浏览器中的视图的URL映射到一个特定的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆