我希望当我的页面(例如 index.jsp
)加载(调用 get 方法)时发送 index.jsp
页面的数据(例如标题)。我检查了这个问题,但这个问题解决方案( How to call servlet on jsp page load )在我的网络应用程序中出现错误。
这是我的 index.jsp
页面代码(我想从 changeTitle.java
类发送标题):
<title><c:import url="/sysAdmin/changeTitle.java" />
<c:out value="${message }"></c:out></title>
这是我的 changeTitle.java
类获取方法:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setAttribute("message", "hello");
}
而且我不知道如何寻址我的项目的 index.jsp
中的类,并且下面是我的项目目录:
最佳答案
尝试设置响应,而不是请求
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setAttribute("message", "hello");
}
关于java - jsp中页面加载时的get方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27579458/