我使用Spring Mvc app
並獲取HTTP狀態[404] - [未找到]。着陸頁即是index.jsp
,Spring Mvc App get - HTTP Status [404] - [Not Found]
,並從控制器的方法調用,
@Controller
public class BitcoinWalletController {
@RequestMapping("/")
public String showBitcoinWallet() {
return "index";
}
}
在index.jsp
頁,寄錢按鈕最初是禁用的,
<div class="buttons_box">
<button type="button" class="btn btn-default btn-lg active" <%= canSendMoney ? "" : "disabled='true'"%>
data-toggle="modal" data-target="#myModal">Send money
</button>
</div>
和僅在同步完成時纔有效,並且boolean canSendMoney
返回true
。
如果按鈕被激活,該代碼處理提供了POST
操作,
<%--modal contents here--%>
<div class="modal-content">
<div class="model-header">
<button type="button" class="close" data-dismiss="modal">×!</button>
<h4 class="modal-title">Send Money</h4>
</div>
<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>
</div>
的sendMoney.jsp
代碼如下規定,
<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>
當我把所有需要的和正確的相關信息和按下按鈕,應該返回原來的頁面 - index.jsp
。相反,我得到的錯誤,HTTP Status [404] – [Not Found]
,
我目前沒有任何句柄地址http://localhost:8080/sendMoney.jsp
。因爲,如果POST
提交是正確的,我想重定向到「/」。
我有jsps
在項目目錄中WEB-INF
文件夾,
在dispatcher-servlet.xml
文件中提供的jsps
位置,
<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>
的we.xml
知道哪裏dispatcher-servlet.xml
位於,
<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>
如何解決這個問題?謝謝。
POST請求假設爲在控制器的方法。 '/ sendMoney.jsp'實際上是試圖找到映射到控制器但沒有找到任何東西。所以它會拋出404 – Zico
什麼是RequestMapping?它應該返回什麼?我只需要按'send money'按鈕後彈出頁面'sendMoney.jsp',然後重定向到'index.jsp'(地址'http:// localhost:8080) – Arefe
'一個控制器接收POST請求。在該控制器中執行'..money.send()'以及其他事情。然後從控制器重定向到'/'。 – Zico