Results 1 to 4 of 4
- 11-23-2011, 01:16 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 9
- Rep Power
- 0
can we get the control back to the jsp page after displaying data through servlet ?
I am displaying the data(String Array) through the servlet . Now I want to pass the same string array tojsp page.
I tried to pass with Session.setAttribute and in get the array with session.getAttribute in jsp as well as with response.setAttibute and response.getAttribute in jsp but was not successful.
can anyone guide me pls.
Thanks
- 11-23-2011, 01:33 PM #2
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
Re: can we get the control back to the jsp page after displaying data through servlet
Can we have a look in your code?
Swastik
- 11-23-2011, 02:04 PM #3
Member
- Join Date
- Nov 2011
- Posts
- 9
- Rep Power
- 0
Re: can we get the control back to the jsp page after displaying data through servlet
following mvc pattern - am trying to implement autocomplete using jquery plugin.am getting the location values properly want to retrieve its id also.
jsp page -
<script>
HttpSession session1=request.getSession();
String buff[][]=session1.getAttribute("locBuffer");
System.out.println("i am in jsp again");
System.out.println(buff[0][0]);
System.out.println(buff[0][1]);
</script>
</head>
<body>
<div style="width: 300px; margin: 50px auto;">
<b>Location </b> : <input type="text" id="location" name="location" class="input_text" onselect="getLocationID()"/>
<br/> <br/><input type="hidden" id="locID" name="locID" class="input_text" />
// want to display its id in the hidden field
</div>
</body>
<script>
jQuery(function()
{
$("#location").autocomplete("servlet/getList");
});
</script>
<script>
// searching the selected location and getting its id from the buffer which is retrieved from the servlet
function getLocationID()
{
location=$("#location").val();
for(int i =0;i<buff.length;i++)
{
if(buffer[i][0].equals(location))
{
int locid=buffer[i][1];
}
}
System.out.println(locid);
$("#locID").value=locid;
}
</script>
and in servlet :getList.java
String query = (String)request.getParameter("q");
System.out.println(query);
Master ms=new Master();
String buffer[][]= ms.retrieveAutoLocation(query); //getting the values loc id and location in string 2d array
System.out.println("bk in servlet ");
HttpSession session = request.getSession();
session.setAttribute("locBuffer", buffer);
int cnt=1;
for(int i=0;i<buffer.length;i++)
{
//if(buffer[i].toUpperCase().startsWith(query.toUpperCase()))
//{
response.getWriter().print(buffer[i][1]+"\n");
if(cnt>=10)
break;
// cnt++;
//}
}
RequestDispatcher rs=getServletContext().getRequestDispatcher("/index.jsp");
rs.forward(request, response);
am not getting the o/p.
am i proceeding the rite way? is there any other alternative fr it? pls guide.
- 11-24-2011, 01:18 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,470
- Rep Power
- 16
Re: can we get the control back to the jsp page after displaying data through servlet
That first <script> block looks like you're trying to write Java in a Javascript area...
What is it you are trying to do?
It seems to be an auto-complete Ajax type call?
In which case "get(ing) the control back to the jsp page" makes no sense...you pass the data from the servlet to the client, which is Javascript by that point.
Similar Threads
-
Go back to previous page using session in JSP page
By gopikarikati009 in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 06-23-2011, 10:30 AM -
Displaying results from the servlet to jsp web page
By rushhour in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 12-17-2010, 12:13 PM -
Java in control pannel is not displaying
By pinki in forum Suggestions & FeedbackReplies: 10Last Post: 08-26-2010, 07:42 AM -
posting results back to parent page
By carag in forum New To JavaReplies: 0Last Post: 07-29-2009, 12:29 PM -
how to use back bean JSF page?
By deru4jesus in forum JavaServer Faces (JSF)Replies: 1Last Post: 03-27-2009, 08:51 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks