import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class LoginServlet extends HttpServlet
{
private void sendLoginPage (HttpServletResponse res, HttpServletRequest req, boolean error)
throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter o = res.getWriter();
o.println("<html><head><title>Sample Login Page</title></head><body>Welcome to Login Page : ");
if (error)
o.println("<fieldset><legend>Login Form : </legend>");
o.println("Login Failed, Please Try Again");
o.println("<form method="+"post"+">");
o.println("<br/><input type="+"text"+"value="+"username"+"/>");
o.println("<br/><input type="+"password"+"value="+""+"/>");
o.println("<br/><input type="+"button"+"value="+"Submit"+"/>");
o.println("</form></fieldset></body></html>");
}
public void doGet (HttpServletResponse res, HttpServletRequest req)
throws ServletException,IOException
{
sendLoginPage (res, null, false) ;
}
public void doPost (HttpServletResponse res, HttpServletRequest req)
throws ServletException,IOException
{
String username = req.getParameter("username");
String password = req.getParameter("password");
if (username.equals("*******") && password.equals("*******"))
{
res.sendRedirect ("http://localhost:7001/ten/r1");
}
else
{
sendLoginPage (res, null, true) ;
}
}
}
さて、このサーブレットがエラーなしで大丈夫コンパイルしても、サーバー に配備が、URLを介してアクセスしようとすると、このエラーを示しています:GETはこのURLによってサポートされていないなぜ「HTTPメソッドGETはこのURLでサポートされていません」というエラーが表示されますか?
HTTPメソッド
可読性を高めるためにコードをインデントすることは許可されています。あなたのIDEは、キーを押すだけでIDEを自動的に実行することさえできるかもしれません。 –