我越來越HTTP狀態405 - HTTP GET方法不受此URL支持 - 我沒有使用任何框架
HTTP狀態405 - HTTP GET方法不受此URL錯誤 的支持我的申請
。請看這三個文件,並建議我有什麼問題。
網址:
ComplaintServlet.java
@WebServlet("/ComplaintServlet")
public class ComplaintServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String frm = request.getParameter("from").trim();
String to = request.getParameter("to").trim();
String c = request.getParameter("dept");
int dept = 0;
dept = Integer.parseInt(c);
response.setContentType("text/plain");
PrintWriter pw = response.getWriter();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:DSN_CCRF","sa","developer1");
PreparedStatement ps = con.prepareStatement("SELECT * FROM Complaints WHERE ComplaintDept=? AND CONVERT(VARCHAR(10),ComplaintDate,105) BETWEEN ? AND ?");
ps.setInt(1,dept);
ps.setString(2,frm);
ps.setString(3,to);
ResultSet rs = ps.executeQuery();
while(rs.next()){
pw.println("<table class='table table-bordered'><thead><tr><th>Title</th></tr></thead><tbody><tr><td>asd</td></tr></tbody></table>");
}
}catch(ClassNotFoundException e){
pw.println("Class Not Found. "+e);
}catch(Exception e){
pw.println("Failed. "+e);
}
}
}
ViewComplaints.jsp
<%@ page import="servlets.DBConnection,java.sql.*,java.util.*,java.io.*" %>
<!DOCTYPE html>
<html>
<head>
<title>Consumer Complaints Redressal Forum</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='../css/bootstrap.min.css' rel="stylesheet">
<link href='../css/bootstrap-theme.min.css' rel="stylesheet">
<link href='../css/style.css' rel="stylesheet">
</head>
<body>
<script src="../js/jquery.js"></script>
<script src='../js/bootstrap.min.js'></script>
<!-- datepicker-->
<script src="../js/jquery-ui.js"></script>
<link rel="stylesheet" href="../css/jquery-ui.css" />
<!-- end datepicker-->
<script type="text/javascript">
$(function() {
$('#txt_frm_date').datepicker({ dateFormat: "dd-mm-yy" }).val();
$('#txt_to_date').datepicker({ dateFormat: "dd-mm-yy" }).val();
});
/* $(document).ready(function() {
$('#btn_get_data').click(function(e){
e.preventDefault();
$.ajax({
url : '../admin/com.do',
data : {
from : $('#txt_frm_date').val(),
to : $('#txt_to_date').val(),
dept : $('#select_dept').val()
},
success : function(response) {
//$('.op').html(response);
alert(response+'as');
}
});
});
});*/
</script>
<div class='container'>
<%@include file="header.jsp"%>
<div class='main'>
<div class="panel panel-primary">
<div class="panel-body">
<% if(session.getAttribute("USER_NAME") == null || session.getAttribute("USER_NAME") == "" || session.getAttribute("USER_TYPE") == "U"){%>
You don't have permission to access this page..!
<%}else{%>
<div class="panel panel-primary">
<div class="panel-heading">
<a href='index.jsp' class='h pull-left'>Home</a> You are logged in as <strong><%=session.getAttribute("USER_NAME")%></strong> (<a class='logout' href='logout.jsp'>Log out</a>)
</div>
<div class="panel-body">
<form class="form-inline" role="form" name='frm-get-data' id='frm-get-data' method='GET' action='../admin/ComplaintServlet.do'>
<div class="form-group">
<input type="text" class="form-control" id="txt_frm_date" name='txt_frm_date' placeholder='From Date:'>
</div>
<div class="form-group">
<input class="form-control" type="text" id="txt_to_date" name='txt_to_date' placeholder='To Date:'>
</div>
<div class="form-group">
<select class="form-control" name='select_dept' id='select_dept'>
<%
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
try{
DBConnection conObj = new DBConnection();
Connection conn = conObj.DbCon();
PreparedStatement ps = conn.prepareStatement("SELECT * FROM Departments ORDER BY DeptID");
ResultSet rs = ps.executeQuery();
%>
<option value=0>ALL</option>
<%
while(rs.next()){
//pw.println(rs.getString("DeptName"));
%>
<option value=<%=rs.getString("DeptID")%>><%=rs.getString("DeptName")%></option>
<%
}
}catch(ClassNotFoundException e){
pw.println("Class Not Found. "+e);
}catch(Exception e){
pw.println("Failed to retrieve departments. "+e);
}
%>
</select>
</div>
<button class="btn btn-primary" name='btn_get_data' id='btn_get_data'>Get it!</button>
</form>
<div class='op'></div>
</div>
</div>
<%}%>
</div>
</div>
</div>
</div>
</body>
</html>
的web.xml
<web-app version="2.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xsi:schemalocation="http:/java.sun.com/dtd/web-app_2_3.dtd">
<servlet>
<servlet-name>ComplaintServlet</servlet-name>
<servlet-class>servlets.ComplaintServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ComplaintServlet</servlet-name>
<url-pattern>/admin/ComplaintServlet.do</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>DBConnection</servlet-name>
<servlet-class>servlets.DBConnection</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DBConnection</servlet-name>
<url-pattern>/DBConnection</url-pattern>
</servlet-mapping>
的網址是什麼那拋出405狀態?將其粘貼在問題 – Zasz 2015-04-04 03:04:39
是的,我已經添加了。謝謝 – user1835613 2015-04-04 03:35:16
你可以試試'http:// localhost:8080/admin/ComplaintServlet.do?txt_frm_date = 01-04-2015&txt_to_date = 30-04-2015&select_dept = 1&btn_get_data ='和'http:// localhost:8080/ComplaintServlet?txt_frm_date = 01-04-2015&txt_to_date = 30-04-2015&select_dept = 1&btn_get_data =' 您在註解「@ WebServlet」中的URL模式或者在「web.xml」中的模式應與您打開該應用的URL匹配。由於你的路徑中有'/ ccrf /',它們都不匹配。 – Zasz 2015-04-04 03:54:52