• 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

Connecting an applet to my struts data

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a functioning struts web application.
I want to display some graphics based on data from my web application and my current thinking is to have an applet on a page which gets it's data from a servlet (or an struts action) and renders the appropriate images.

I have written the applet and have all my data in one object but connecting from the applet to a struts action just seems wrong and I can't seem to add another servlet into web.xml without the rest of the application breaking either (are you even really meant to use other servlets when you are using struts?).

Am I going about this all wrong? Is there an easier way?
Any help would be appreciated.
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is wrong in connecting the applet to your struts?
 
Matthew Plant
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure how to do it.

Do I create a new servlet which sits alongside the struts action servlet and define this in web.xml and use this to serve my applet the required data?

Or can I connect the applet to a struts action directly?

Or is there another more elegant solution?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Matt-

Welcome to JavaRanch.

On your way in you may have missed that we have a policy on screen names here at JavaRanch. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.

As to your question, using a Struts action would seem weird - not nearly as natural as using a servlet directly. That is definitely possible, though, in addition to using the Struts servlet. What problems are you facing in particular setting that up?
 
Matthew Plant
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote a httpservlet (would genericservlet be better) and added in the definitions into web.xml but then I could not load jsp pages from my struts application and so I wondered if adding additional servlets interrupted the normal flow of the actionservlet and requests to it and should be avoided.

Also I didn't know if my servlet was actually running or not.

It made me sad... :-(
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Extending HttpServlet is the way to go. How are you mapping the servlet in the web.xml file? It sounds as if there may be an overlap between the servlet mapping and the Struts mapping.
 
Matthew Plant
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Erm something like:

<servlet>
<servlet-name>custom</servlet-name>
<servlet-class>test.servlet.CustomServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>custom</servlet-name>
<url-pattern>/custom</url-pattern>
</servlet-mapping>

not quite sure how the url pattern should look for what I am trying to do...

Also I noticed the struts action servlet defination has this extra bit within the servlet tags. <load-on-startup>2</load-on-startup>. Maybe I need one of those in my servlet definition?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
load-on-startup has nothing to do with this.

What happens if you try to access the servlet? Have you tried it from within a browser?

Assuming that the Struts servlet is not mapped to "/custom" it should work.
 
Matthew Plant
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I finally got it to work and I haven't broken struts!!!
Thanks for your help with this.

Think I was mostly doing things right but a couple of things tripped me up...

1. I think I was initially missing a slash in the servlet mapping which was breaking struts.

2. Then when I got the networking code sussed and the applet worked standalone but not embedded in a JSP I realised struts was helpfully sticking ".do" onto the end of my request to the servlet.

Changed the servlet mapping to the following and it ALL worked.

<servlet-mapping>
<servlet-name>custom</servlet-name>
<url-pattern>/Custom.servlet</url-pattern>
</servlet-mapping>

Now if I can only remember what I was originally trying to achieve... ;-)

Thanks again, great forum.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you specify what you'd like to draw? If you're using Struts 2 maybe something like the JFreeChart Plugin or Connext Graph Plugin might be helpful for you.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic