如何在Struts2.x中添加漂亮的URL? [英] How to wtite pretty URL in Struts2.x?

查看:101
本文介绍了如何在Struts2.x中添加漂亮的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Struts2中重写我的URL. 请帮我做到这一点.我如何根据需要进行自定义,我不想显示我要传递的参数,也不想显示我想要的其他名称的动作 我不知道该怎么做.我必须为此使用插件或在struts.xml

I want to rewrite my URL in Struts2. Please help me out to do this. How can i customize as i want, i don't want to show my parameter that i am passing and also show action with different name that i want I don't know how to do it. i have to use plugins for that or configure my code in struts.xml

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <constant name="struts.action.extension" value="action" />
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="true" />
    <constant name="struts.ui.theme" value="simple" />  


    <include file="struts-user.xml"></include>
    <include file="struts-admin.xml"></include>
    <include file="struts-common.xml"></include>
    <include file="struts-masters.xml"></include>
</struts>

文件告诉我如何执行以及给我解决方案.

file tell me the way how to perform as well as give me solution.

我的网址就是这样

/operations/MatchPredictionLevel2_index.action?sgt=102&lvl2=1&tn=MatchPredictionLevel2

我想向用户显示类似于/operations/prediction的url,并且我想根据其目的针对所有URL进行同样的操作

i want to show my url like /operations/prediction to user and the same thing i want to do for all URL based on its purpose i want rewrite url

推荐答案

如果您不想显示传递的参数,则可以使用解决方案.

If you don't want to show the parameter passing you could use this solution.

要真正隐藏传递的参数,您需要提交表单.您应避免click事件的默认行为,并将其替换为form事件.

To hide passed parameter actually you need to submit the form. You should prevent the default behavior of the click event and replace it with the form event.

如果您还想显示其他名称的操作,则可以使用上面的过滤器或

If you also want to show action with different name, you can use the above filter or wildcard mapping.

高级通配符

从2.1.9+起可以在action中定义正则表达式 姓名.要使用这种形式的通配符,必须将以下常量 设置:

Advanced Wildcards

From 2.1.9+ regular expressions can be defined defined in the action name. To use this form of wild card, the following constants must be set:

<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
<constant name="struts.patternMatcher" value="regex" />

正则表达式可以有两种形式,最简单的一种是 {FIELD_NAME},在这种情况下, 操作将使用匹配的文本填充,例如:

The regular expressions can be in two forms, the simplest one is {FIELD_NAME}, in which case the field with the FIELD_NAME in the action will be populated with the matched text, for example:

<package name="books" extends="struts-default" namespace="/">
    <action name="/{type}/content/{title}" class="example.BookAction">
  <result>/books/content.jsp</result>
    </action>
</package>

这篇关于如何在Struts2.x中添加漂亮的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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