• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

doPost() not happening

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am trying to create a servlet that will open a pdf document based on the passing the MIME header.

So I made my action ServletRequestAware. I am using struts 2. I then placed the doPost() in the action and set the form in the jsp to post to this action. It does not seem to be doing the do post. Any ideas?

Action:
public class CWABillA extends ActionSupport implements ServletRequestAware


Struts.xml:
<action name="ShowBillPDF" class="com.mudnebr.cwa.action.CWABillA" >
<result>/tiles/keepScreen.jsp</result>
</action>

web.xml:
<servlet>
<servlet-name>CWABillA</servlet-name>
<servlet-class>com.mudnebr.cwa.action.CWABillA</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CWABillA</servlet-name>
<url-pattern>/CWABillA.action</url-pattern>
</servlet-mapping>
jsp:
<s:form action="CWABillA.action" method="post" theme="simple">
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im no expert in struts 2 but shouldnt the action name in your jsp <s:form tag and struts.xml be the same?
 
Katie Doody
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess not, this was already set up this way and it is definitely calling the action but it is not doing the doPost(). If I was starting it new I would keep them the same but I don't have to rewrite it. I have put messages in and it goes through the action but never gets to the do post. Am I making a bad assumption since this action class is really a servlet that it will do the doPost()?
[ November 02, 2007: Message edited by: Katie Doody ]
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will need to make up your mind: Either write a servlet or write a Struts 2 Action class. It can't be both. Since you declared the class as a Struts action class, that's how it's functioning, and the doPost method is never called.
 
Katie Doody
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to get the action class to call the servlet? The action class finds the document and downloads the document to a common location.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need it to be a Servlet? There's nothing a Servlet can do that an Action class can't do.
 
Katie Doody
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to use mime to open a pdf. I think this has to be done in a doPost() that is why I thought of adding the doPost to my action class because I thought the action class could do anything a servlet could do but on the other hand i wanted to keep the servlet that opens pdf's separate so that I could reuse it.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am pretty sure that the only thing that implementing the ServletRequestAware interface does is tell Struts to populate the request (HttpServletRequest) property of your action class. It does not change your action into a servlet.

- Brent
 
Katie Doody
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried this both ways but i am not sure how to tell the action to invoke the servlet. I am really looking for some help, i know that the way i am doing it does not seem to be working. I would really appreciate some help even if it is just pointing me in the right direction.
 
Katie Doody
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So would it be faux pas to extend HttpServlet in my action class so I can use the doPost() method?
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not understand why you think you need to do your processing in a doPost method. I have only played around a little with Struts 2, but I am pretty sure you can get at the request and response objects (yep, I see a ServletResponseAware interface as well) so it seems like you could do all your processing in your action.

- Brent
 
Katie Doody
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I bet that is my problem. I was having a problem with the response.getoutputstream being null. I bet if I use the response aware it will work. Thank you so much.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!