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();
}
4

1 回答 1

0

您可以使用Parameters after the Action name.

要在 URL 中使用参数,请确保在操作名称之后设置:

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

然后动作映射将如下所示:

<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>

当请求/edit/person/123之类的 URL 时,将调用EditAction ,其“ id ”字段将设置为123

于 2013-04-24T15:01:24.590 回答