我关注了这篇文章并创建了一个自定义 URL 应用程序。正在调用该操作,但 url 显示会话 ID,例如
http://localhost:8080/CustomURL%7Busername%7D.action;jsessionid=9C1FB3EB633209C18625BBB40EA61000
我只想喜欢http://localhost:8080/CustomURL/rajesh
见我的struts.xml
:
<struts>
<constant name="struts.mapper.alwaysSelectFullNamespace"
value="false" />
<constant name="struts.enable.SlashesInActionNames" value="true" />
<constant name="struts.patternMatcher" value="namedVariable" />
<package name="default" namespace="/" extends="struts-default">
<action name="">
<result name="success">home.jsp</result>
</action>
<action name="{username}" class="com.rajesh.struts2.CustomURL"
method="customUrl">
<result name="success">welcome.jsp</result>
</action>
</package>
查看我的 JSP 页面:
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Struts 2 Custom URL</title>
</head>
<body>
<h1>Struts 2 Custom URL</h1>
<h3>Enter your name below</h3>
<s:form action="{username}">
<s:textfield name="username" />
<s:submit />
</s:form>
</body>
</html>
请参阅下面的 java 文件:
public class CustomURL extends ActionSupport {
private String username;
public String getUsername() {
System.out.println("Getter");
return username;
}
public void setUsername(String username) {
System.out.println("Setter");
this.username = username;
}
private static final long serialVersionUID = -4337790298641431230L;
public String customUrl() {
return SUCCESS;
}
}