• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

call a servlet from a jsp????

 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am developing a website using jsp's. I had planned to use jsp's for every page, but I need to use a graphing product (EasyCharts at www.objectplanet.com) that requires the graph to be built in a servlet NOT a jsp. I am saving the values to be graphed in various java beans. I know this is probably an elementary question, but can someone please tell me how to call the servlet from my jsp, how to pass the values from the bean to the servlet, and how to get from the servlet to a jsp? Can one jsp call the servlet and then be called when the servlet is finished, or does this require the use of at least two servlets? Any suggestions and/or examples is greatly appreciated!!
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To call a servlet from a JSP, try...
<jsp: forward page="../servlets/YourServlet" />
Then to set some values to a bean, in YourServlet do this.
...
SomeBean obj = new SomeBean();
obj.setValues("yourvalues");
// forward to a jsp
RequestDispatcher newJSP = getServletContext().getRequestDispatcher("/xxx/yyy/next.jsp");
newJSP.forward(req,res);
Hope this helps
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Use send HttpServletResponse.sendRedirect() or RequestDispatcher.forward() methods. See API for more complete information.
 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies. Just a few more questions:
How do I set values in the bean from the jsp so that they are in the bean when I am in the servlet? See, I start with a jsp; I need to set values from this jsp and then go to the servlet. I thought that the form had to be submitted in the jsp to get the values set in the bean. Any ideas?
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi fox,
U need to do the following steps
<jsp:useBean id="mybean" scope="session" class="storeBean"/>
.....
.....
<%
int yourvalue=10;
mybean.storeValue(yourvalue);
out.println("The value in the bean is "+storeBean.value);
// or u can use
out.println("The value in the bean is "+mybean.retrieveValue());
%>
storeBean.java
--------------
public class storeBean
{
public int value;
public storeBean()
{}
public void storeValue(int value)
{
this.value=value;
}
public int retrieveValue()
{
return this.value
}
}

I hope i fulfilled your request..
Best Regards,
Paramaguru.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic