Luc
Luc

Reputation: 2805

Struts 2 - How to use package in URL

I would like to build a dynamic web project like that:

Method: GET | POST | DELETE API URL: http://example.com/api/

Example:

So can you help me How can I do it by using STRUTS 2. Please explain something about it if you can.

Upvotes: 0

Views: 173

Answers (2)

Dave Newton
Dave Newton

Reputation: 160181

Use the S2 REST plugin.

It sets up everything you need, including result type mapping based on request URL. You might need to do some tweaking for the multi-level bits. If it doesn't work out-of-the-box, you can use the following along with various URL mapping options (including the package namespacing mentioned by Kartik).

Alternatively, you could do it manually using a combination of parameter name matching and the JSON plugin (or use whatever result types you need).

Upvotes: 1

Kartik73
Kartik73

Reputation: 513

You can do this by using namespace attribute of the Package tag in your struts configuration file struts.xml.

Below is the example for doing this.

<package name="user" namespace="/User" extends="struts-default">
<action name="Login">
    <result>pages/login.jsp</result>
</action>
</package>

Upvotes: 1

Related Questions