【发布时间】:2018-08-09 03:35:06
【问题描述】:
我想知道如何从 servlet 获取和发布,并在 jsp 页面中使用 jquery ajax 即获取响应并发布它。我已经完成了 doget。如果可能的话,我想从我的 jsp 中删除 jstl页面。请帮助我。提前致谢
这是我的控制器类
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//get the data from database ie the model class
try {
List<Script> scriptitems=modelDBUtil.getScriptList();
request.setAttribute("scriptItems", scriptitems);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*String itemsfood[]={"biriyani","rice"};
request.setAttribute("itemsfood",itemsfood)*/;
//redirect to a different page
RequestDispatcher dispatcher =request.getRequestDispatcher("scriptviewer.jsp");
dispatcher.forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
}
现在我的jsp页面请帮帮我
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Menu</title>
</head>
<body>
<p>Script Items</p>
<c:forEach var="items" items="${scriptItems}">
${items.id} ${items.command}
</c:forEach>
<form action="appendfile.jsp" method="post">
<select name="department">
<c:forEach var="item" items="${scriptItems}">
<option value="${item.id}">${item.command}</option>
</c:forEach>
</select>
<button type="submit" id="idsubmit">Submit</button>
</form>
</body>
</html>
【问题讨论】:
-
您的问题和代码不清楚。你在问什么?你能解释一下你想说什么吗?请花一些时间阅读帮助页面,stackoverflow.com/help/how-to-ask
-
我已经编辑了...现在
标签: javascript jquery ajax jsp servlets