[英]Jsp request is not going to java servlet class
我有一個表,其中包含帶有查看,更新,刪除圖標的記錄。 在點擊查看和更新時,我正在將我的請求傳遞給其他jsp。 在單擊刪除圖標時,請求需要進入我的servlet類。 在那里應該執行刪除查詢。
這是我的桌子
在單擊刪除圖標時,我正在獲取ID,並在網址中刪除值。 看到圖像。 但是請求不會發送到Java servlet。
這是我的代碼
Jsp代碼:
<%
FormRegistration fr = new FormRegistration();
List<UserDetailsBean> list = fr.getUserDetails();
%>
<form method="post" action="./BrightSymphonyController" >
<%
for(int i=0;i<list.size();i++){
%>
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th style="display: none;">ID</th>
</tr>
</thead>
<tbody>
<td>
<a href="./BrightSymphonyController?id=<%=list.get(i).getId()%>&delete=Delete" class="urlImgDelete" title="Delete"><!--here i have delete icon -->
</a>
</td>
<%}%>
</tbody>
</table>
</form>
Servlet類:
@WebServlet("/BrightSymphonyController")
public class BrightSymphonyController extends HttpServlet {
/**
* @see HttpServlet#HttpServlet()
*/
public BrightSymphonyController() {
//super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String deleteuser = request.getParameter("delete");
System.out.println("deleteuser============"+deleteuser);
String id=request.getParameter("id");
System.out.println("id============"+id);
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>brightsymphony</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>BrightSymphony</servlet-name>
<servle-class>com.s2s.brightsymphony.controller.BrightSymphonyController
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BrightSymphony</servlet-name>
<url-pattern>/BrightSymphony</url-pattern>
</servlet-mapping>
</web-app>
請幫我。
您正在發送get參數,將代碼從doPost()移至doGet()方法,如下所示
@WebServlet("/BrightSymphonyController")
public class BrightSymphonyController extends HttpServlet {
/**
* @see HttpServlet#HttpServlet()
*/
public BrightSymphonyController() {
//super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String deleteuser = request.getParameter("delete");
System.out.println("deleteuser============"+deleteuser);
String id=request.getParameter("id");
System.out.println("id============"+id);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
將代碼從doPost()
移至doGet()
href
發送的請求get
不post
,您使用的不是form
發送請求post
您的請求從發送href
如果您希望將請求作為post
發送
<form method="post" action="./BrightSymphonyController" >
<%
for(int i=0;i<list.size();i++){
%>
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th style="display: none;">ID</th>
</tr>
</thead>
<tbody>
<td>
<input type="submit" class="urlImgDelete" value="Delete" />
<input type="hidden" name="id" value="<%=list.get(i).getId()%>"/>
<input type="hidden" name="delete" value="Delete" />
</td>
<%}%>
</tbody>
</table>
</form>
寫這個
<a href="<%=request.ContextPath()%>/BrightSymphonyController?id=<%=list.get(i).getId()%>&delete=Delete" class="urlImgDelete" title="Delete">
裝的
<a href="./BrightSymphonyController?id=<%=list.get(i).getId()%>&delete=Delete" class="urlImgDelete" title="Delete">
我希望這個能幫上忙!!!!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.