老师i,帮忙看看有什么完善的,另外最后四行的前三行与第四行可不可以换换顺序
package el; public class Course { private int id; private String name; private String category; public int getId() { return id; } public void setId(int 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() { String describe="这是一个特别重要的学科!"; return describe; } }
package el; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet("/servlet/handle") public class ServletHandle extends HttpServlet { private static final long serialVersionUID = 1L; public ServletHandle() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Course course = new Course(); course.setId(17234); course.setName("英语"); course.setCategory("必修"); request.setAttribute("course", course); request.getRequestDispatcher("/CourseExhibition.jsp").forward(request, response); } }
<%@ 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> <p>id:${requestScope.course.id }</p> <p>名称:${requestScope.course.name }</p> <p>所属方向:${requestScope.course.category }</p> <p>课容量:${param.capacity }</p> <p>${requestScope.course }</p> </body> </html>
//course.setId(17234);
//course.setName("英语");
//course.setCategory("必修");
//request.setAttribute("course", course);
15
收起
正在回答
1回答
同学你好,1. 已完成练习,棒棒哒!继续加油!
2. 同学描述的是否是下方代码,如果是,则属性赋值(set()方法)与setAttribute()方法替换顺序是可以的。
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
2. 从网页搭建入门JavaWeb
- 参与学习 人
- 提交作业 676 份
- 解答问题 9666 个
本阶段将从前端网页搭建入手,到Java Web基础,前后端结合助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星