How to call custome URL action from Form action?

前端 未结 3 2028
陌清茗
陌清茗 2020-12-20 09:53

I followed this post and created a custom URL application. The action is getting called but the url shows with session id like

http://localhost:8080/CustomURL

相关标签:
3条回答
  • 2020-12-20 09:55

    First of all you should get rid of action extension, if you don't want user to think their name has an extension.

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

    Next the pattern matcher should be regex.

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

    Action mapping

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

    In the JSP you don't need to use form tag, but anchor tag. And use known names.

    <a href="http://localhost:8080/CustomURL/rajesh">Click my name</a>
    
    0 讨论(0)
  • 2020-12-20 10:06

    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.

    0 讨论(0)
  • 2020-12-20 10:21

    try it..

     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;
     }
    
    0 讨论(0)
提交回复
热议问题