eclipseで勉強中です。以下のコードが参考書に出ていて、ブラウザでテストしたいのですが
「HTTPステータス 405 - Method Not Allowed
Type ステータスレポート
メッセージ HTTPのGETメソッドは、このURLではサポートされていません。
説明 The method received in the request-line is known by the origin server but not supported by the target resource.
Apache Tomcat/9.0.7」
のエラーが出てしまいます。似たようなコードがこの前にあって、正常に動いたので、同じようにやったのですが、いくらやってもできないのでお助けください。
いつもコードの打ち込みミスで怒られていますので、朝から何回も見直したのですがうまくいきません。
コードが正常かどうか知りたいのですが宜しくお願い致します。
package sample6; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Servlet implementation class SampleServlet6_03 */ @WebServlet("/sample6") public class SampleServlet6_06 extends HttpServlet { private static final long serialVersionUID = 1L; public SampleServlet6_06() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { super.doGet(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); String str = request.getParameter("text1"); out.println("</body><html>"); out.println("<h1>あなたは、「" + str + "」と書きました。</h1>"); out.println("</body></html>"); } }
回答1件
あなたの回答
tips
プレビュー