0

この投稿に従って、カスタム URL アプリケーションを作成しました。アクションが呼び出されていますが、URL は次のようなセッション ID で表示されます

http://localhost:8080/CustomURL%7Busername%7D.action;jsessionid=9C1FB3EB633209C18625BBB40EA61000

私は単に好きですhttp://localhost:8080/CustomURL/rajesh

私を参照してくださいstruts.xml:

<struts>
<constant name="struts.mapper.alwaysSelectFullNamespace"
    value="false" />
<constant name="struts.enable.SlashesInActionNames" value="true" />
<constant name="struts.patternMatcher" value="namedVariable" />
<package name="default" namespace="/" extends="struts-default">
    <action name="">
        <result name="success">home.jsp</result>
    </action>

    <action name="{username}" class="com.rajesh.struts2.CustomURL"
        method="customUrl">
        <result name="success">welcome.jsp</result>
    </action>

</package>

私のJSPページを見てください:

<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Struts 2 Custom URL</title>
</head>
<body>
    <h1>Struts 2 Custom URL</h1>
    <h3>Enter your name below</h3>
    <s:form action="{username}">
        <s:textfield name="username" />
        <s:submit />
    </s:form>
</body>
</html>

以下の Java ファイルを参照してください。

public class CustomURL extends ActionSupport {

    private String username;

    public String getUsername() {
        System.out.println("Getter");
        return username;
    }

    public void setUsername(String username) {
        System.out.println("Setter");
        this.username = username;
    }

    private static final long serialVersionUID = -4337790298641431230L;

    public String customUrl() {
        return SUCCESS;
    }
}
4

3 に答える 3

0

Try $ before {username}. $ Stands for Freemarker

<action name="{username}" class="com.rajesh.struts2.CustomURL" 
 method="customUrl">

Freemarker Tutorial

How to use OGNL Expression Example link

<s:property value="username"/> for calling username on welcome page.

It may help you to get your answer.

于 2014-05-23T04:37:55.470 に答える
0

ユーザーに自分の名前に拡張子があると思わせたくない場合は、まずアクション拡張子を削除する必要があります。

<constant name="struts.action.extension" value=",,action"/> 

次に、パターンマッチャーはregex.

<constant name="struts.patternMatcher" value="regex"/>

アクション マッピング

<action name="/CustomURL/{username}" class="com.rajesh.struts2.CustomURL" method="customUrl">
    <result name="success">welcome.jsp</result>
</action>

JSP では、タグを使用する必要はありませんがform、アンカー タグを使用します。そして、既知の名前を使用します。

<a href="http://localhost:8080/CustomURL/rajesh">Click my name</a>
于 2014-05-23T06:07:15.830 に答える
0

それを試してみてください..

 public String customUrl() {

   HttpServletRequest request=(HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
   String url="http://"+request.getServerName()+":"+request.getServerPort()+""+request.getContextPath()+"/"+request.getParameter("username");

   logger.info(" Current url : "+url);  //check it here

    return SUCCESS;
 }
于 2014-05-23T05:42:12.807 に答える