Liberty Profile 服务器根据请求执行不正确的功能
Liberty Profile server executing incorrect function on request
前言:Tomcat 或 Tomee 服务器没有这个问题。
我试图通过 ajax 执行一个简单的 Get 请求,当请求到达服务器时它执行了错误的方法。
JS文件
function CustomerPoints() {
this.initializeListeners = function () {
$("#storeSelect").change(function (event) {
event.preventDefault();
customerPoints.callAjax(contextPath + "/loyaltyPoints/customerPoints?getPoints&id=" + $("#storeSelect").val());
});
this.callAjax = function (url, value) {
// generated url = http://localhost:9080/TLC/loyaltyPoints/customerPoints?getPoints&id=3778
var cardNumber = $("#customerNumber");
var alternateId = $("#alternateId");
$
.ajax(
url,
{
type: "GET",
data: value,
beforeSend: function (req) {
$("#modalErrorDiv").empty();
req.setRequestHeader("Accept",
"text/html;type=ajax");
req.setRequestHeader($(
"meta[name='_csrf_header']").attr(
"content"), $("meta[name='_csrf']")
.attr("content"));
},
complete: function (jqXHR) {
$("#customerNumber").replaceWith(cardNumber);
$("#alternateId").replaceWith(alternateId);
customerPoints.initializeListeners();
},
success: function (data, textStatus, jqXHR) {
$("#content").replaceWith(data);
},
error: function (jqXHR, textStatus, errorThrown) {
$('html,body').animate({
scrollTop: $('body').offset().top
}, 'slow');
$("#modalErrorDiv").empty();
$("#modalErrorDiv")
.append("<ul ><li class='error'>An error has occured. Please contact support.</li></ul>");
}
});
};
控制器
@Controller
public class CustomerPointsController
{
private static final String HTML_PAGE = "loyaltyPoints/customerPoints";
private static final String REQUESTMAPPING = "/" + HTML_PAGE;
private static final String APPLYPOINTSMAPPING = "loyaltyPoints/applyPoints :: #content";
private static final String CONTENT = HTML_PAGE + " :: #content";
/**
* @param model
* @return
*/
@RequestMapping(value = REQUESTMAPPING)
public String maintainCustomerPoints(Model model)
{
// this is the method that is called everytime
return HTML_PAGE;
}
/**
* @param id
* @param model
* @returns the valid customer points for this store, default followed by promotion points
* when a user picks a store from the drop down.
*/
@RequestMapping(value = REQUESTMAPPING, method = RequestMethod.GET, params = {
"getPoints"})
public String getPoints(@RequestParam(value = "id") String id, Model model)
{
// this is the method that never gets called
return CONTENT;
}
}
注意我还从页面脚本中获取了生成的 URL 并粘贴到我的浏览器中以执行。它只执行 maintainCustomerPoints
.
server.xml
<?xml version="1.0" encoding="UTF-8"?>
<server description="tlc server">
<!-- Enable features -->
<featureManager>
<feature>jsf-2.0</feature>
<feature>jsp-2.2</feature>
<feature>ssl-1.0</feature>
<feature>localConnector-1.0</feature>
<feature>restConnector-1.0</feature>
<feature>json-1.0</feature>
<feature>jaxrs-1.1</feature>
<feature>servlet-3.0</feature>
<feature>jpa-2.0</feature>
<feature>beanValidation-1.0</feature>
<feature>jndi-1.0</feature>
<feature>jdbc-4.0</feature>
<feature>monitor-1.0</feature>
</featureManager>
<httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9080" httpsPort="9443" virtualHost="default_host" />
<jdbcDriver id="DerbyJDBCDriver">
<library name="DerbyLib">
<fileset dir="C:\tools\servers\wlp\lib" includes="derbyclient-10.6.1.0.jar" />
</library>
</jdbcDriver>
<dataSource jndiName="jdbc/TLCDataSource" id="derbyDataSource" jdbcDriverRef="DerbyJDBCDriver">
<properties.derby.client databaseName="TLC" password="APP" user="APP" />
</dataSource>
<applicationMonitor updateTrigger="mbean" />
<application id="TLC_war" context-root="/TLC" location="C:\Users\nd26434\gitrepos\tlc\target\TLC-1.0.0-SNAPSHOT.war" name="TLC_war" type="war">
<classloader delegation="parentLast">
<privateLibrary>
<fileset dir="C:\tools\servers\wlp\lib" includes="aspectjweaver-1.8.0.jar" />
</privateLibrary>
</classloader>
</application>
</server>
根据documentation @RequestMapping
,如果在{"myParam"}
形式中有params
,则假定该参数必须出现在请求中并且可以具有任何值.
所以 URL 的安全形式应该包含 getPoints
的任何值,例如 customerPoints?getPoints=anyValueHere
.
可能是 request.getParameter()
方法 return 对 Tomcat 的不同值,当没有值时。对于自由它 return null
如果没有 =
,就像 customerPoints?getPoints
和 non null
当有 =
像 customerPoints?getPoints=
前言:Tomcat 或 Tomee 服务器没有这个问题。
我试图通过 ajax 执行一个简单的 Get 请求,当请求到达服务器时它执行了错误的方法。
JS文件
function CustomerPoints() {
this.initializeListeners = function () {
$("#storeSelect").change(function (event) {
event.preventDefault();
customerPoints.callAjax(contextPath + "/loyaltyPoints/customerPoints?getPoints&id=" + $("#storeSelect").val());
});
this.callAjax = function (url, value) {
// generated url = http://localhost:9080/TLC/loyaltyPoints/customerPoints?getPoints&id=3778
var cardNumber = $("#customerNumber");
var alternateId = $("#alternateId");
$
.ajax(
url,
{
type: "GET",
data: value,
beforeSend: function (req) {
$("#modalErrorDiv").empty();
req.setRequestHeader("Accept",
"text/html;type=ajax");
req.setRequestHeader($(
"meta[name='_csrf_header']").attr(
"content"), $("meta[name='_csrf']")
.attr("content"));
},
complete: function (jqXHR) {
$("#customerNumber").replaceWith(cardNumber);
$("#alternateId").replaceWith(alternateId);
customerPoints.initializeListeners();
},
success: function (data, textStatus, jqXHR) {
$("#content").replaceWith(data);
},
error: function (jqXHR, textStatus, errorThrown) {
$('html,body').animate({
scrollTop: $('body').offset().top
}, 'slow');
$("#modalErrorDiv").empty();
$("#modalErrorDiv")
.append("<ul ><li class='error'>An error has occured. Please contact support.</li></ul>");
}
});
};
控制器
@Controller
public class CustomerPointsController
{
private static final String HTML_PAGE = "loyaltyPoints/customerPoints";
private static final String REQUESTMAPPING = "/" + HTML_PAGE;
private static final String APPLYPOINTSMAPPING = "loyaltyPoints/applyPoints :: #content";
private static final String CONTENT = HTML_PAGE + " :: #content";
/**
* @param model
* @return
*/
@RequestMapping(value = REQUESTMAPPING)
public String maintainCustomerPoints(Model model)
{
// this is the method that is called everytime
return HTML_PAGE;
}
/**
* @param id
* @param model
* @returns the valid customer points for this store, default followed by promotion points
* when a user picks a store from the drop down.
*/
@RequestMapping(value = REQUESTMAPPING, method = RequestMethod.GET, params = {
"getPoints"})
public String getPoints(@RequestParam(value = "id") String id, Model model)
{
// this is the method that never gets called
return CONTENT;
}
}
注意我还从页面脚本中获取了生成的 URL 并粘贴到我的浏览器中以执行。它只执行 maintainCustomerPoints
.
server.xml
<?xml version="1.0" encoding="UTF-8"?>
<server description="tlc server">
<!-- Enable features -->
<featureManager>
<feature>jsf-2.0</feature>
<feature>jsp-2.2</feature>
<feature>ssl-1.0</feature>
<feature>localConnector-1.0</feature>
<feature>restConnector-1.0</feature>
<feature>json-1.0</feature>
<feature>jaxrs-1.1</feature>
<feature>servlet-3.0</feature>
<feature>jpa-2.0</feature>
<feature>beanValidation-1.0</feature>
<feature>jndi-1.0</feature>
<feature>jdbc-4.0</feature>
<feature>monitor-1.0</feature>
</featureManager>
<httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9080" httpsPort="9443" virtualHost="default_host" />
<jdbcDriver id="DerbyJDBCDriver">
<library name="DerbyLib">
<fileset dir="C:\tools\servers\wlp\lib" includes="derbyclient-10.6.1.0.jar" />
</library>
</jdbcDriver>
<dataSource jndiName="jdbc/TLCDataSource" id="derbyDataSource" jdbcDriverRef="DerbyJDBCDriver">
<properties.derby.client databaseName="TLC" password="APP" user="APP" />
</dataSource>
<applicationMonitor updateTrigger="mbean" />
<application id="TLC_war" context-root="/TLC" location="C:\Users\nd26434\gitrepos\tlc\target\TLC-1.0.0-SNAPSHOT.war" name="TLC_war" type="war">
<classloader delegation="parentLast">
<privateLibrary>
<fileset dir="C:\tools\servers\wlp\lib" includes="aspectjweaver-1.8.0.jar" />
</privateLibrary>
</classloader>
</application>
</server>
根据documentation @RequestMapping
,如果在{"myParam"}
形式中有params
,则假定该参数必须出现在请求中并且可以具有任何值.
所以 URL 的安全形式应该包含 getPoints
的任何值,例如 customerPoints?getPoints=anyValueHere
.
可能是 request.getParameter()
方法 return 对 Tomcat 的不同值,当没有值时。对于自由它 return null
如果没有 =
,就像 customerPoints?getPoints
和 non null
当有 =
像 customerPoints?getPoints=