关于EL无法正确显示信息的问题
来源:6-3 自由编程
慕娘2318419
2019-04-04 19:11:08
这是CourseServlet.java
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;
/**
* Servlet implementation class CourseServlet
*/
@WebServlet("/cs" )
public class CourseServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public CourseServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
Course cou = new Course();
cou.setName("数学");
cou.setId("C001");
cou.setCategory("science");
request.setAttribute("course", cou);
request.getRequestDispatcher("/course.jsp").forward(request, response);
}
这是course.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="com.imooc.lianxi.Course"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>课程名:${requestScope.course.name }</h1>
<h1>课程编号:${requestScope.course.id }</h1>
<h1>课程方向:${requestScope.course.category }</h1>
</body>
</html>
1回答
你好!我运行了你的代码,是可以显示成功的,没问题,你看一下地址,是不是访问的Servlet。此处要先访问Servlet,由Servlet转发给jsp进行显示,否则没有数据。
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
相似问题