【发布时间】:2014-08-07 04:45:52
【问题描述】:
当我调用该页面时,我想在我的网页中重新加载一些内容。
<jsp:include page ="/GetAllDetailsOfFollowing" /><br>
我已经从一个 jsp 页面调用了一个 servlet。但是在网页上它并没有完全执行。然后我必须手动刷新网页,然后它将显示所有文档。 如何解决这个问题呢。 jquery中是否有任何方法可以在重新加载网页后立即重新加载此页面 这是我在 servlet 中的 doGet 方法
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
Connection con = null;
HttpSession session=request.getSession();
String followingPerson=(String)session.getAttribute("followingPerson");
String userName =(String)session.getAttribute("userName");
PreparedStatement st = null;
List dataListDetails = new ArrayList();
List dataListTweets = new ArrayList();
List dataListFollwers = new ArrayList();
List dataListFollowing = new ArrayList();
ResultSet rsForProfile = null, rsForTweets = null, rsForFollower = null, rsForFollowing = null;
try {
con = ConnectionManager.getConnection();
String sql="select * from person where user_id=\""+followingPerson+"\"";
//sql = "select * from person where user_id=\"ankur\"";
// sql="select * from person where user_id=\""+followingPerson+"\"";
st = con.prepareStatement(sql);
st.executeQuery();
rsForProfile = st.getResultSet();
if (rsForProfile.next()) {
dataListDetails.add("First Name");
dataListDetails.add(rsForProfile.getString("firstName"));
dataListDetails.add("Full Name");
dataListDetails.add(rsForProfile.getString("fullName"));
dataListDetails.add("User Id");
dataListDetails.add(rsForProfile.getString("user_id"));
dataListDetails.add("Email Id");
dataListDetails.add(rsForProfile.getString("email_id"));
dataListDetails.add("Joined At");
dataListDetails.add(rsForProfile.getString("joined"));
}
request.setAttribute("dataListDetails", dataListDetails);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
rsForProfile.close();
rsForTweets.close();
rsForFollower.close();
rsForFollowing.close();
st.close();
con.close();
} catch (SQLException s) {
}
}
RequestDispatcher rd = request
.getRequestDispatcher("GetAllDetailOfFollowing.jsp");
if (rd != null) {
rd.include(request, response);
}
}
这是我从 jsp 调用的 jsp
<body>
<table border ="1" cellpadding="1" style="margin-left: 511px; margin-top: 56px;">
<%
Iterator itr;
List data =(List)request.getAttribute("dataListDetails");
for(itr=data.iterator();itr.hasNext();){
%>
<tr>
<td width="119"><%=itr.next() %></td>
<td width ="168"><%=itr.next() %></td>
</tr>
<%
}
request.removeAttribute("dataListDetails");
%>
</table>
基本上,我在启动 jsp 时包含 servlet,然后该 servlet 包含另一个 jsp。最后一个 jsp 将在网页上打印一个故事,但是当我刷新网页时,它将可见。还告诉如何从 jsp 页面中删除 scriplet。
【问题讨论】:
-
向我们展示您调用 servlet 的代码?
-
我已将 servlet 包含在 JSP 中。上面我已经写好了代码。
-
所以这个包含的页面 (
GetAllDetailsOfFollowing) 调用 servlet 并返回一些东西?向我们展示 GetAllDetailsOfFollowing 页面 -
谁能帮我解决这个问题