aspose file tools*
The moose likes Servlets and the fly likes call a servlet from a jsp???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "call a servlet from a jsp????" Watch "call a servlet from a jsp????" New topic
Author

call a servlet from a jsp????

verduka fox
Ranch Hand

Joined: Jan 18, 2001
Posts: 178
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!!
Shuaib Gill
Ranch Hand

Joined: May 29, 2001
Posts: 62
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


programmer77
Andrey Opanasets
Greenhorn

Joined: Aug 14, 2001
Posts: 17
Hi
Use send HttpServletResponse.sendRedirect() or RequestDispatcher.forward() methods. See API for more complete information.
verduka fox
Ranch Hand

Joined: Jan 18, 2001
Posts: 178
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?
Paramagurusamy Balasubramanian
Ranch Hand

Joined: Aug 17, 2001
Posts: 55
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: call a servlet from a jsp????