关于doGet和doPost
package com.imooc.ELandJSP.el.JSTL;
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 java.io.IOException;
@WebServlet("/jstl")
public class Servlet1 extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
/* request.setAttribute("score", 78);
request.setAttribute("grade", "B");
request.getRequestDispatcher("/JSTL/core.jsp").forward(request, response);*/
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setAttribute("score", 78);
request.setAttribute("grade", "B");
request.getRequestDispatcher("/JSTL/core.jsp").forward(request, response);
}
}
<%--
Created by IntelliJ IDEA.
User: 丁大伟
Date: 2020/3/15
Time: 16:42
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>Title</title>
</head>
<body >
<h1>${requestScope.score}</h1>
<c:if test="${score>=60}">
<h1 style="color:green">恭喜,你已经通过测试</h1>
</c:if>
<c:if test="${score<60}">
<h1 style="color:red">对不起,再接再厉</h1>
</c:if>
</body>
</html>
我想问一下,为什么我在doGet方法中写的就可以在浏览器中显示,在doPost方法就不能在浏览器中显示,我贴的代码中doGet和doPost方法中的代码完全相同
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 277 份
- 解答问题 4297 个
Java数据库开发的必备技能,从流行的MySQL数据库开始,到Java原生的数据库管理接口JDBC的使用,再到常用的数据持久化框架MyBatis,让你向Java工程师的目标又迈进了一步!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星