I work with Spring Mvc and have the controller returns the index.jsp
page,
@Controller
public class BitcoinWalletController {
@RequestMapping("/")
public String showBitcoinWallet() {
return "index";
}
}
This is the index.jsp
page,
The code to handle the submission operation (inside the index.jsp
),
<form id="send-form" class="form-horizontal" action="sendMoney.jsp" method="POST">
<div class="modal-body">
<div class="form-group">
<label for="amount" class="col-sm-2 control-label">Send</label>
<div class="col-xs-4">
<input id="amount" name="amount" class="form-control" value="0">
</div>
<div class="btc-col">
<span>BTC</span>
</div>
</div>
<div class="form-group">
<label for="address" class="col-sm-2 control-label">to</label>
<div class="col-sm-10">
<input id="address" name="address" class="form-control">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-default">Send</button>
</div>
</form>
The code for the sendMoney.jsp
provided,
<%@ page import="com.puut.bitcoin.WalletSendMoneyController" %>
<html>
<body>
<%
String amount = request.getParameter("amount").trim();
String address = request.getParameter("address").trim();
WalletSendMoneyController.getSendMoneyController().send(address, amount);
// New location to be redirected
String site = new String("/");
response.setStatus(response.SC_MOVED_TEMPORARILY);
response.setHeader("Location", site);
%>
</body>
</html>
I expect that after the submission of the pop-up, I should redirected to the original index.jsp
page.
Instead, I get the following error,
HTTP Status [404] – [Not Found] after the submission
The app structure,
The jsps location provided in the dispatcher-servlet.xml file,
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsps/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
The web.xml knows where the dispatcher-servlet.xml is located,
<servlet>
<description></description>
<display-name>dispatcher</display-name>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I have no other mapping
then the @RequestMapping("/")
.
If I remove the action="sendMoney.jsp"
from the index.jsp
and have another controller with the POST
method as suggested, I get the following stack of errors,
Type Exception Report
Message Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.springframework.http.MediaType.compareTo(Lorg/springframework/http/MediaType;)I
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.springframework.http.MediaType.compareTo(Lorg/springframework/http/MediaType;)I
org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1259)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
How to solve the issue? Thanks.
Please to try handle the Post Request from controller
and on sendMoney.jsp you can get the parametres puted on the modelMap :
For best practices do not include java code on jsp file