3) JSP 响应隐式对象

2025 年 3 月 17 日 | 阅读 1 分钟

在 JSP 中,response 是 HttpServletResponse 类型的隐式对象。HttpServletResponse 的实例由 Web 容器为每个 jsp 请求创建。

它可以用于添加或操作响应,例如将响应重定向到另一个资源,发送错误等。

让我们看看 response 隐式对象的示例,我们正在将响应重定向到 Google。

response 隐式对象的示例

index.html
<form action="welcome.jsp">
<input type="text" name="uname">
<input type="submit" value="go"><br/>
</form>
welcome.jsp
<% 
response.sendRedirect("http://www.google.com");
%>

输出

jsp response implicit object output 1