I am unable to retrieve the value from DB. Please go through the code and guide me in solving it
public ArrayList getReqResInfo(String id)
{
String methodname="createConnection";
Connection conn = null;
ResultSet rs=null;
PreparedStatement psmt;
int req_id=0;
String reqid=id;
ArrayList resList=new ArrayList();
try {
conn = DBConnection.getJNDIConnection();
System.out.println("getReqResInfo id=="+reqid);
psmt= conn.prepareStatement("select * from CR_REQUEST_RESOURCE_INFO where REQUEST_ID=?");
psmt.setInt(1,Integer.parseInt(id));
rs= psmt.executeQuery();
System.out.println("getReqResInfo");
while(rs.next())
{
System.out.println(rs.getString("RES_LEVEL") +" " + rs.getString("NOOF_RES") +" " + rs.getString("RES_PRIMARY_SKILL") +" " + rs.getString("RES_QUALIFICATION") +" " + rs.getString("RES_SECONDARY_SKILL") +" " + rs.getString("RES_EXP"));
ReqResourceVO resourceVO=new ReqResourceVO();
resourceVO.setLevel(rs.getString("RES_LEVEL"));
resourceVO.setNumres(rs.getString("NOOF_RES"));
resourceVO.setPrimary(rs.getString("RES_PRIMARY_SKILL"));
resourceVO.setQualification(rs.getString("RES_QUALIFICATION"));
resourceVO.setSecondary(rs.getString("RES_SECONDARY_SKILL"));
resourceVO.setYear(rs.getString("RES_EXP"));
resList.add(resourceVO);
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try {
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
return resList;
}
In the servlet I am calling this function as mentioned below
if(action.equals("view"))
{
try
{
String reqid=req.getParameter("id");
System.out.println("id "+reqid);
ReqProjVO reqProjVO=new ReqProjVO();
reqProjVO.setRequestid(reqid);
ReqResDAO reqresDAO=new ReqResDAO();
reqProjVO=reqresDAO.getReqProjInfo(reqProjVO);
ArrayList resVOList=reqresDAO.getReqResInfo(reqid);
req.setAttribute("projVO", reqProjVO);
HttpSession session = req.getSession(true);
session.setAttribute("resVOList", resVOList);
ReqProjDAO reqprojDAO=new ReqProjDAO();
ArrayList projList=reqprojDAO.Project();
req.setAttribute("projList", projList);
System.out.println("in request resource servlet");
RequestDispatcher rd= req.getRequestDispatcher("jsp/manager/RequestforResource.jsp");
rd.forward(req,res);
System.out.println("in request resource servlet");
}
catch(Exception e)
{
e.printStackTrace();
}
}
Values are being fetched from the DB and it is printed on the console but it is not forwarding to the concerned JSP page it is going to the log in JSP page and I am getting this huge error. I dont know what to do...
java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at weblogic.utils.io.ChunkedOutputStream.writeTo(ChunkedOutputStream.java:193)
at weblogic.servlet.internal.ResponseHeaders.writeHeaders(ResponseHeaders.java:434)
at weblogic.servlet.internal.ServletResponseImpl.writeHeaders (ServletResponseImpl.java:1256)
at weblogic.servlet.internal.ServletOutputStreamImpl.sendHeaders(Servlet OutputStreamImpl.java:244)
at weblogic.servlet.internal.ChunkOutput.flush(ChunkOutput.java:379)
at weblogic.servlet.internal.ChunkOutput.checkForFlush(ChunkOutput.java:469)
at weblogic.servlet.internal.ChunkOutput.write(ChunkOutput.java:304)
at weblogic.servlet.internal.ChunkOutputWrapper.write(ChunkOutputWrapper.java:139)
at weblogic.servlet.jsp.JspWriterImpl.write(JspWriterImpl.java:274)
开发者_运维技巧 at jsp_servlet._jsp._manager.__requestforresource._jspService(__requestforresource.java:237)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run (StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.ServletStubImpl.onAddToMapException(ServletStubImpl.java:408)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:318)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:505)
at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:251)
at manager.RequestResourceServlet.doPost(RequestResourceServlet.java:181)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3498)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
The method you have shown us (getReqResInfo()
) does not appear in the stack trace. The only part of the stack trace that appears to be in your own code is manager.RequestResourceServlet.doPost()
, so it's likely the problem lies there. If you can find the problem yourself in RequestResourceServlet.java:181
then great! Otherwise, provide more code.
Extra helpful advice for you:
Your method returns an ArrayList
. Better to specify the interface type, List
instead (best practise: program to interfaces rather than concrete types so they can easily be changed later). Also, note that List
s are generic. You should specify that your list is a list of ReqResourceVO
, so write List<ReqResourceVO>
. Using generics means your collection is type-safe and you don't need extra casting later.
It's good to see that you know how to use finally
to close the connection at the end, but don't forget to also close the resultset and the statement. :)
This exception occurs when a client made a request, and before receiving the full response, either of the following happened:
- client's browser has been closed.
- client's connection has been disconnected.
- client presses the stop button.
More info.
In req.getRequestDispatcher call my interest points to the path of the jsp page. Should you try starting it with a slash / like many examples I have found are starting? So it starts /jsp/ instead of plain jsp/
精彩评论