Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4772

Convention Plugin can't use ${message}

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Not A Problem
    • Affects Version/s: 2.5.10
    • Fix Version/s: 2.5.12
    • Component/s: Plugin - Convention
    • Labels:
    • Environment:

      Windows10+JDK7.0_80+tomcat7.0.76

    • Docs Text:
      Struts 2.5.10.1

      Description

      today i fount the plugin maybe have an issue.

      public class HelloWorldAction extends ActionSupport {
      	private String message;
      
      	public String getMessage() {
      		return message;
      	}
      
      	public void setMessage(String message) {
      		this.message = message;
      	}
      
      	public String execute() {
      		message = "Hello World, I come from Action Code";
      		return SUCCESS;
      	}
      }
      

      HelloWorld.jsp

       This is  ${message}   // the message is null and the action can't be called.
      

        Activity

        Hide
        newton_dave Dave Newton added a comment -

        Can you provide more details?

        Show
        newton_dave Dave Newton added a comment - Can you provide more details?
        Hide
        fairy fairy added a comment -

        sure, you can download Project

        Test Project Demo
        Download link:http://pan.baidu.com/s/1boYgCbH
        password:293b

        Show
        fairy fairy added a comment - sure, you can download Project Test Project Demo Download link: http://pan.baidu.com/s/1boYgCbH password:293b
        Hide
        newton_dave Dave Newton added a comment -

        fairy Do you have a version that doesn't rely on Eclipse, e.g., a Maven-based project?

        Show
        newton_dave Dave Newton added a comment - fairy Do you have a version that doesn't rely on Eclipse, e.g., a Maven-based project?
        Hide
        fairy fairy added a comment -

        sorry, I'm not familiar with a maven project, so I have just convert it to a maven project with tools , Could you check it whether it is ok ?

        Maven Project:
        http://pan.baidu.com/s/1kU8NQXD

        password:jyj7

        Show
        fairy fairy added a comment - sorry, I'm not familiar with a maven project, so I have just convert it to a maven project with tools , Could you check it whether it is ok ? Maven Project: http://pan.baidu.com/s/1kU8NQXD password:jyj7
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        fairy can you attach the project here?

        Show
        lukaszlenart Lukasz Lenart added a comment - fairy can you attach the project here?
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        I am not able to reproduce the issue using my own Convention based project.

        Show
        lukaszlenart Lukasz Lenart added a comment - I am not able to reproduce the issue using my own Convention based project.
        Hide
        fairy fairy added a comment -

        hi Lukasz lenart ,this is the project.

        Show
        fairy fairy added a comment - hi Lukasz lenart ,this is the project.
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        Can you attach the Maven project?

        Show
        lukaszlenart Lukasz Lenart added a comment - Can you attach the Maven project?
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        or attach packaged war file

        Show
        lukaszlenart Lukasz Lenart added a comment - or attach packaged war file
        Hide
        lukaszlenart Lukasz Lenart added a comment - - edited

        The case is that the Convention plugin is not able locate your action, it directly maps to the JSP - /HelloWorld request is mapped to WEB-INF/content/HelloWorld.jsp.

        You must tell the Convention plugin where your actions are by setting struts.convention.action.packages constant, i.e.

        <constant name="struts.convention.action.packages" value="actions"/>
        
        Show
        lukaszlenart Lukasz Lenart added a comment - - edited The case is that the Convention plugin is not able locate your action, it directly maps to the JSP - /HelloWorld request is mapped to WEB-INF/content/HelloWorld.jsp . You must tell the Convention plugin where your actions are by setting struts.convention.action.packages constant, i.e. <constant name= "struts.convention.action.packages" value= "actions" />
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        hm... but I see some other problem

        Show
        lukaszlenart Lukasz Lenart added a comment - hm... but I see some other problem
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        You are using wrong action name, camel case actions are converted into urls with dashes:

        com.example.actions.MainAction -> /main
        com.example.actions.products.Display -> /products/display
        com.example.struts.company.details.ShowCompanyDetailsAction -> /company/details/show-company-details
        

        so in your example /hello-world and JSP must also be named hello-world.jsp or success.jsp or hello-world-success.jsp

        Show
        lukaszlenart Lukasz Lenart added a comment - You are using wrong action name, camel case actions are converted into urls with dashes: com.example.actions.MainAction -> /main com.example.actions.products.Display -> /products/display com.example.struts.company.details.ShowCompanyDetailsAction -> /company/details/show-company-details so in your example /hello-world and JSP must also be named hello-world.jsp or success.jsp or hello-world-success.jsp
        Hide
        fairy fairy added a comment -

        Hi ,Thanks for your help very much, I have fixed the problem with your method.
        Summary point of attention:
        action name and jsp name and url mapping relationship
        a. if our action name have two or more words, action name every word had better First name is capitalized,like HelloWorldAction.

        1. it is not required,because the constant will convert action name to lower case
          <constant name="struts.convention.action.name.lowercase" value="true" />
          b. if our action name is HelloWorldAction,so our jsp name must be split between words with '-' , like this hello-world.jsp
          <constant name="struts.convention.action.name.separator" value="-" />
          c. the Suffix default is action ,so our URL must be is hello-world.action or hello-world
        2. the URL mapping should be hello-world.action ,It should be noted that it is not helloworld.action
          <constant name="struts.convention.action.suffix" value="action" />
          d.Set the root path for the Convention plug-in location view resource
          <constant name="struts.convention.result.path" value="/WEB-INF/content/" />
          #default is content if you like, you can modify the root path to views
          <constant name="struts.convention.result.path" value="/WEB-INF/views/" />
        Show
        fairy fairy added a comment - Hi ,Thanks for your help very much, I have fixed the problem with your method. Summary point of attention: action name and jsp name and url mapping relationship a. if our action name have two or more words, action name every word had better First name is capitalized,like HelloWorldAction. it is not required,because the constant will convert action name to lower case <constant name="struts.convention.action.name.lowercase" value="true" /> b. if our action name is HelloWorldAction,so our jsp name must be split between words with '-' , like this hello-world.jsp <constant name="struts.convention.action.name.separator" value="-" /> c. the Suffix default is action ,so our URL must be is hello-world.action or hello-world the URL mapping should be hello-world.action ,It should be noted that it is not helloworld.action <constant name="struts.convention.action.suffix" value="action" /> d.Set the root path for the Convention plug-in location view resource <constant name="struts.convention.result.path" value="/WEB-INF/content/" /> #default is content if you like, you can modify the root path to views <constant name="struts.convention.result.path" value="/WEB-INF/views/" />
        Hide
        fairy fairy added a comment -

        thanks for your help,i have fixed it with your method.

        Show
        fairy fairy added a comment - thanks for your help,i have fixed it with your method.
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        Thanks for the summary but I think the same is documented here https://struts.apache.org/docs/convention-plugin.html

        Show
        lukaszlenart Lukasz Lenart added a comment - Thanks for the summary but I think the same is documented here https://struts.apache.org/docs/convention-plugin.html

          People

          • Assignee:
            lukaszlenart Lukasz Lenart
            Reporter:
            fairy fairy
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development