我从Spring API返回了modelAndView对象。而视图是一种JSP形式。 API的请求参数与DTO PaymentInput绑定。 API在localhost上工作正常,但在部署到服务器时它给出了空白响应。我检查了日志,但没有例外。
被修改
当我更改新的ModelAndView(“payuForm”,“paymentInput”,paymentInput); to ModelAndView mav = new ModelAndView(new MappingJackson2JsonView()); 它开始以Json
的形式返回输出 "paymentInput": {
"furl": "https://dev.travelkhana.com/callback/PayUfurl",
"surl": "https://dev.travelkhana.com/callback/PayUsurl",
"txnid": "472663",
"key": "gtKFFx",
"hash": "3c0eeb0cefd5c0637e0a50adee3fd0fe81af6c69f46a52b2fa50711eafa054b43af13957c02ef3a71c0dbcb8c05129829281fd256a55c0c0c04bbc40c84fd474",
"orderid": "472663",
"email": "test@test.com",
"emailid": "test@test.com",
"amount": "270",
"productinfo": "vegthali,nonvegthali",
"firstname": "rahul",
"phone": "9716221914"
}
但仍不适用于HTML响应。
payuForm.jsp
<%@page import="com.tk.utilities.CommonFunction"%>
<%
String paymentUrl = CommonFunction.getProperties("payu_payment_url");
System.out.println("paymentUrl:"+paymentUrl);
%>
<html>
<head>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
</head>
<body>
<form:form action="<%=paymentUrl%>" method="post" id='payuForm' modelAttribute="paymentInput">
<form:input type="hidden" name="firstname" path="FIRSTNAME"/>
<form:input type="hidden" name="surl" path="surl"/>
<form:input type="hidden" name="furl" path="furl" />
<form:input type="hidden" name="phone" path="PHONE" />
<form:input type="hidden" name="email" path="EMAIL" />
<form:input type="hidden" name="amount" path="AMOUNT" />
<form:input type="hidden" name="key" path="key" />
<form:input type="hidden" name="hash" path="hash" />
<form:input type="hidden" name="txnid" path="txnid" />
<form:input type="hidden" name="productinfo" path="PRODUCTINFO" />
<input type="hidden" name="isMobileView" value="1" />
</form:form>
</body>
</html>
模型类
package com.tk.payu.dto;
public class PaymentInput {
private String AMOUNT;
private String ORDERID;
private String PRODUCTINFO;
private String FIRSTNAME;
private String EMAIL;
private String EMAILID;//for mapping EMAILID to EMAIL
private String PHONE;
private String furl;
private String surl;
private String txnid;
private String key;
private String hash;
PaymentInput.java
public String getFurl() {
return furl;
}
public void setFurl(String furl) {
this.furl = furl;
}
public String getSurl() {
return surl;
}
public void setSurl(String surl) {
this.surl = surl;
}
public String getTxnid() {
return txnid;
}
public void setTxnid(String txnid) {
this.txnid = txnid;
}
public String getAMOUNT() {
return AMOUNT;
}
public void setAMOUNT(String aMOUNT) {
AMOUNT = aMOUNT;
}
public String getORDERID() {
return ORDERID;
}
public void setORDERID(String oRDERID) {
ORDERID = oRDERID;
}
public String getPRODUCTINFO() {
return PRODUCTINFO;
}
public void setPRODUCTINFO(String pRODUCTINFO) {
PRODUCTINFO = pRODUCTINFO;
}
public String getFIRSTNAME() {
return FIRSTNAME;
}
public void setFIRSTNAME(String fIRSTNAME) {
FIRSTNAME = fIRSTNAME;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
public String getPHONE() {
return PHONE;
}
public void setPHONE(String pHONE) {
PHONE = pHONE;
}
public String getEMAIL() {
return EMAIL;
}
public void setEMAIL(String eMAIL) {
EMAIL = eMAIL;
}
public String getEMAILID() {
return EMAILID;
}
public void setEMAILID(String eMAILID) {
EMAILID = eMAILID;
}
}
控制器
@RequestMapping(value = "/payuPaymentNew", method = RequestMethod.POST)
public @ResponseBody ModelAndView payuPaymentNew(
@ModelAttribute("paymentInput") PaymentInput paymentInput,
BindingResult result) throws IOException {
String SURL = CommonFunction.getProperties("payu_surl");
String FURL = CommonFunction.getProperties("payu_furl");
System.out.println("order id:" + paymentInput.getORDERID());
String salt = CommonFunction.getProperties("salt");
String key = CommonFunction.getProperties("key");
paymentInput.setSurl(SURL);
paymentInput.setFurl(FURL);
paymentInput.setKey(key);
System.out.println("payumasterDao:.....");
return new ModelAndView("payuForm", "paymentInput", paymentInput);
}
预期产出
<html>
<head>
</head>
<body>
<form id="payuForm" action="" method="post">
<input id="FIRSTNAME" name="FIRSTNAME" name="firstname" type="hidden" value="rahul"/>
<input id="surl" name="surl" name="surl" type="hidden" value=""/>
<input id="furl" name="furl" name="furl" type="hidden" value="/>
<input id="PHONE" name="PHONE" name="phone" type="hidden" value="9716221914"/>
<input id="EMAIL" name="EMAIL" name="email" type="hidden" value="test@test.com"/>
<input id="AMOUNT" name="AMOUNT" name="amount" type="hidden" value="270"/>
<input id="key" name="key" name="key" type="hidden" value=""/>
<input id="hash" name="hash" name="hash" type="hidden" value="3c0eeb0cefd5c0637e0a50adee3f/>
<input id="txnid" name="txnid" name="txnid" type="hidden" value="472663"/>
<input id="PRODUCTINFO" name="PRODUCTINFO" name="productinfo" type="hidden" value="vegthali,nonvegthali"/>
<input type="hidden" name="isMobileView" value="1" />
</form>
</body>
</html>
XML条目
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
答案 0 :(得分:0)
从控制器中删除@ResponseBody
。
@ResponseBody
注释基本上是告诉Spring:将对象I(方法)返回并使用任何支持它的序列化程序并将其直接写入HTTP响应的主体。 这里没有涉及JSP 。