Question: I am trying to pass a key value in query string from one page to another in a project using the Struts 2 framework.

**URL Mapping:**

```xml
<struts>        
    <package name="default" namespace="/" extends="struts-default">

        <!-- Line -->
        <action name="line" class="com.example.a.b.action.LineAction">
            <result name="success">/line.jsp</result>
        </action>

    </package>

</struts>

```

**URL For HTML Anchor Link:**

```
http://localhost/line?key=value

```

When it goes to `LineAction` I want to get the query string key value part but could find anything online for it.

Answer: 
The problem is your database model, you can fix with a quest if the depth will always be three or less, but this is not a nice solution. Maybe a idea to read the following article on hierarchical data in MySQL: <http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/>
you could write a stored-procedure that creates a temporary table and loop through each node and insert category until the parent is NULL then SELECT from that temporary table ORDER by reverse order so that higher nodes will show up first and then drop that temporary table when you're done like this [sqlFiddle](http://sqlfiddle.com/#!2/5bdfa/1/5)

```
CREATE PROCEDURE get_hierchy(IN in_category varchar(50))
BEGIN
 CREATE TEMPORARY TABLE _categories(id int auto_increment primary key,category varchar(50));
 SET @category = NULL;
 SET @parent = in_category;
 WHILE(@parent IS NOT NULL) DO
    SET @nextparent = @parent;
    SET @parent = NULL;
    SELECT category,parent INTO @category,@parent FROM categories WHERE category = @nextparent;
    INSERT INTO _categories(category) values (@category);
 END WHILE;
 SELECT category FROM _categories ORDER BY id DESC;
 DROP TABLE _categories;
END//  

```

or if you have an `auto_incremented id` in your `categories` table and if you know the nodes that are higher up in the hierarchy will always be created first before lower nodes you can use this query ([sqlFiddle](http://sqlfiddle.com/#!2/77e31/10/0))

```
SELECT category
FROM
  (SELECT @parent:=parent as newparent,
          category,parent,
          id
   FROM categories
   JOIN(SELECT @parent:='leasing-steps')init
   WHERE category = @parent
   ORDER BY id DESC
   )cat
ORDER BY id ASC

```