我無法讓頁面正常工作,我正在做的是當我單擊鏈接時,它應該連接到數據庫並將數據顯示到瀏覽器。HTTP方法GET不受此URL支持-java servlets
這是我的JSP代碼:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<%
String str = (String)request.getAttribute("acId");
%>
Account ID: <a href="detailsservlet"> <%= str %>
</body>
</html>
這是我的servlet代碼:
package com.Project.Hdfc;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class detailsservlet extends HttpServlet {
@Override
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
Connection con;
Statement stmt;
ResultSet rs;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:DSN","scott","krishna");
stmt = con.createStatement();
rs = stmt.executeQuery("Select * from custm");
pw.println("Id "+ " Name" +" Address" + "<br>");
while(rs.next())
{
pw.println(rs.getInt(1)+" "+rs.getString(2) + " " + rs.getString(3) + "<br>");
}
}
catch (Exception e){
pw.println(e);
}
}
}
仍然收到相同的錯誤。 – 2012-03-13 16:41:30
@krishnabhargavi現在編輯答案。從現在開始,您是否嘗試過使用最簡單的解決方案來添加doGet方法,如示例中的答案? – rapadura 2012-03-13 16:43:06
是啊我添加了doPost方法仍然我得到相同的錯誤 – 2012-03-13 16:45:21