permaculture playing cards*
The moose likes Servlets and the fly likes Need help with a servlet problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Need help with a servlet problem" Watch "Need help with a servlet problem" New topic
Author

Need help with a servlet problem

pradeep andhra
Greenhorn

Joined: Sep 18, 2006
Posts: 9
Hello Java Gurus,

I am working on a simple web project and need help with a problem.

The index.jsp has 2 iframe components, where the src attribute for each iframe references to a separate jsp page (so the src for iframe1 is iframe1.jsp and for iframe2, its iframe2.jsp)

Now, the iframe2.jsp has a search text and a submit button. On entering a search text, the control goes to a servlet, which then runs some logic and sends an object to be displayed in iframe1.

In the servlet, I have used RequestDispatcher to forward the response to iframe1. Now, the problem here is that the response is getting populated in iframe2.jsp itself (from where the initial request originated). I need to response to go to iframe1.jsp

Have verified all the links and paths in the code, so there isn’t any typo anywhere. Just wondering what might be wrong here. Is RequestDispatcher not the right way to send control to another jsp? If yes, what is the other alternative?

Please advise.

Thanks,
B.S.S
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

This problem may occur because

1.When you are testing your webapps try to clear the history of the browser after sometime because older code get reflected again and again and you think there is error is you code.but actually browser is behaving differently

2.Can you please tell which server you are using.have you deployed your war file on server or you are just using eclipse feature.


SCJP6.0,My blog Ranchers from Delhi
pradeep andhra
Greenhorn

Joined: Sep 18, 2006
Posts: 9
Shanky Sohar wrote:This problem may occur because

1.When you are testing your webapps try to clear the history of the browser after sometime because older code get reflected again and again and you think there is error is you code.but actually browser is behaving differently

2.Can you please tell which server you are using.have you deployed your war file on server or you are just using eclipse feature.


Hi Shanky,

I am using netbeans version 6 for my project. I dont think this has anything to do with browser cache or history. Its about the control being passed from servlet to a jsp which is different from the jsp that has initated the request.

Thanks,
B.S.S
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Can you please tell which server you are using and have you deployed your war file on the server.
Kuldip Shetty
Ranch Hand

Joined: Jan 07, 2010
Posts: 39

Hi,

Instead of using the Submit button try using the hyperlink <a href="" target="Frame Name">. Input html tag doesnt have the target attribute but the target attribute is supported in the HTML <a> tag. In case of Submit button the response is redirected to the current frame. Hope this helps in resolving the above problem

Kuldip
Tejas Shah
Greenhorn

Joined: Oct 26, 2009
Posts: 23

Hi,

It seems that you are not having any problem with passing the control. Submit button works just for the form submission and have no responsibility to render pages in specific regions.
You can use hyperlink and java script to handle form submission, and getting it in another frame.

-Tejas
Cherish your life...!!


-Tejas
Cherish your life...!!
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

please post the code..So that we can see.
pradeep andhra
Greenhorn

Joined: Sep 18, 2006
Posts: 9
Tejas Shah wrote:Hi,

It seems that you are not having any problem with passing the control. Submit button works just for the form submission and have no responsibility to render pages in specific regions.
You can use hyperlink and java script to handle form submission, and getting it in another frame.

-Tejas
Cherish your life...!!


Sorry for the delay in replying to this thread.

Tejas - Yes, the problem is similar to what you have stated.

The code below gives you an indication of the issue

index.jsp - the page that contains the 2 iframes



Here is frame1.jsp which is put in a folder named frame1.



Here is frame2.jsp which is put in a folder named frame2.


And finally.. the servlet code


Instead of frame1 getting the message from the servlet, the frame2 is always getting populated with this message.

Please advise.

Thanks,
B.S.S
Kuldip Shetty
Ranch Hand

Joined: Jan 07, 2010
Posts: 39

Pradeep,

As mentioned above did you try using the hyperlink with target attribute instead of submit button. I tried with some sample static HTML files with frames (without using servlets) which uses <a> hyperlink with target attribute and I was able to redirect the response to another frame. But using a submit button, as you mentioned was displayed in the same frame.

Below is the sample of frame2.html which has the hyperlink example



Kuldip
pradeep andhra
Greenhorn

Joined: Sep 18, 2006
Posts: 9
Kuldip Shetty wrote:Pradeep,

As mentioned above did you try using the hyperlink with target attribute instead of submit button. I tried with some sample static HTML files with frames (without using servlets) which uses <a> hyperlink with target attribute and I was able to redirect the response to another frame. But using a submit button, as you mentioned was displayed in the same frame.

Below is the sample of frame2.html which has the hyperlink example



Kuldip


Thanks Kuldip. But I really need to push this to a servlet and that's because I have a whole lot of logic (database calls and dicing the information) at the backend.

Any idea how I can get this done?

Thanks,
B.S.S
 
 
subject: Need help with a servlet problem
 
Similar Threads
Iframe and Struts
Center a iframe
Problem with RequestDispatcher.
how to change url of iframe in javascript
Concept for refreshing a page