0

i am writing the client web jsp page just like having one form(get) with user name search text box and submit button

when the user submits it returns the json format of user

but the url looks like when i submit it

http://myhost.net:8080?user=pavan&method.execute=submit how can i convert this url to below one in struts2 .

http://myhost.net:8080/user/pavan

is there any .htaccess file in struts2

@Results( { @Result(name = "success", type = "redirectAction") })
public class UsersController implements ModelDriven<Object>,
ServletRequestAware {
private String username;
private HttpServletRequest request;
private String representation;

// GET /users/{username}
public HttpHeaders show() {
String acceptHeader = request.getHeader("Accept");
String type = "xml";
if (acceptHeader == null || acceptHeader.isEmpty() ||
acceptHeader.equals("application/xml")) {
representation = UserBO.getXML(username);
} else if (acceptHeader.equals("application/json")) {
representation = UserBO.getJSON(username);
type = "json";
}
return new DefaultHttpHeaders(type).disableCaching();
}
pavan
  • 334
  • 6
  • 20

1 Answers1

0

You can use Parameters after the Action name.

To use parameters in the URL, after the action name, make sure this is set:

<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>

Then the action mapping will look like:

<package name="edit" extends="struts-default" namespace="/edit">
  <action name="/person/*" class="org.apache.struts.webapp.example.EditAction">
      <param name="id">{1}</param>
      <result>/mainMenu.jsp</result>
  </action>   
</package>

When a URL like /edit/person/123 is requested, EditAction will be called, and its "id" field will be set to 123.

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243