问题出在哪里呢?显示405错误

问题出在哪里呢?显示405错误

corse类

package com.course;


public class Course {

private String id;

private String name;

private String category;

public String getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getCategory() {

return category;

}

public void setCategory(String category) {

this.category = category;

}

@Override

public String toString() {

return "Course [id=" + id + ", name=" + name + ", category=" + category + "]";

}

}



Servlet文件

package com.course;


import java.io.IOException;

import java.util.ArrayList;

import java.util.List;


import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;


import com.course.Course;


/**

 * Servlet implementation class CourseServlet

 */

@WebServlet("/index")

public class CourseServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

       

    /**

     * @see HttpServlet#HttpServlet()

     */

    public CourseServlet() {

        super();

        // TODO Auto-generated constructor stub

    }


/**

* @param Course 

* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

*/

protected void doGet(HttpServletRequest request, HttpServletResponse response, Object Course) throws ServletException, IOException {

// TODO Auto-generated method stub

String level = request.getParameter("level");

Course course = new Course();

course.setId("0001");

course.setName("Java");

course.setCategory("计算机类");

request.setAttribute("course", course);

request.getRequestDispatcher("/index.jsp").forward(request, response);

}

}


jsp文件

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<body>

<h2>Id:${requestScope.course.id }</h2>

<h2>Name:${requestScope.course.name }</h2>

<h2>Category:${requestScope.course.category }</h2>

<h2>Level:${param.level }</h2>

</body>

</html>


正在回答

登陆购买课程后可参与讨论,去登陆

1回答

同学,你好!405错误产生的原因一般是请求的方法不存在,比如此时执行Servlet会发送请求到doGet()方法执行,但doGet()方法不支持。http://img1.sycdn.imooc.com//climg/5e5b6c390956ad6a14660354.jpg

查找错误发现:doGet方法中多了一个参数,就不是从HttpServlet继承来的doGet()方法了,因此执行Servlet的时候找不到对应的doGet方法了。修改建议就是把doGet()方法中的第三个参数去掉。http://img1.sycdn.imooc.com//climg/5e5b6da0092b7d1d16440204.jpg


如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师