问题描述
我尝试将短文本从servlet发送到jsp,并在jsp页面上显示该文本。 但是在jsp页面上,我看到“ 空”。
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
Here is some text
<%
Object message=request.getAttribute("message");
out.println(message);
%>
</body>
<%= request.getAttribute("message") %>
</html>
我有一个servlet: DataServlet.java :
package com.servlettojsp;
import java.io.IOException;
import javax.servlet.Requestdispatcher;
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("/DataServlet")
public class DataServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public DataServlet() {
super();
}
protected void doGet(HttpServletRequest request,HttpServletResponse response) throws servletexception,IOException {
String mes="This is a message from the servlet";
request.setAttribute("message",mes);
Requestdispatcher rd= request.getRequestdispatcher("show.jsp");
rd.forward(request,response);
}
protected void doPost(HttpServletRequest request,IOException {
}
}
为什么我不能将数据从servlet传递到jsp?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)