Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't strut with struts!

 
Robert Bonslater
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Every time I call "ValidateEmployee.do" in my inputContent.jsp it directs me to a blank white page on ie with this URL:

http://localhost:8080/begjsp-ch18/validateEmployee.do;jsessionid=32...

It should either go to the outputContent.jsp or revert back to inputContent.jsp containing the errors from MessageResources.properties. ActionServlet obviously found the mapping so I'm not sure what it could possibly be. I am using Tomcat v5 on windows os with the latest version of jakarata struts. Here is some of my information not that it would be of any help:


web.xml
<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>


struts-config.xml
<action path="/validateEmployee"
type="com.example.ValidateEmployeeAction"
name="empForm"
scope="request"
input="/inputContent.jsp"
validate="false">
<forward name="success" path="/outputContent.jsp"/>
</action>

ValidateEmployeeAction.java
public class ValidateEmployeeAction extends Action {

public ActionForward perform(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException {
ActionMessages errors = new ActionMessages();
EmployeeForm empForm = (EmployeeForm)form;
String name = empForm.getName();
if(name.trim().equals("")) {
ActionMessage error = new ActionMessage ("error.missing.name");
errors.add("ActionMessages.GLOBAL_MESSAGE",error);
}
String department = empForm.getDepartment();
if(department.trim().equals("")) {
ActionMessage error = new ActionMessage("error.missing.department");
errors.add("ActionMessages.GLOBAL_MESSAGE",error);
}

String[] skills = empForm.getSkills();
if(skills == null) {
ActionMessage error = new ActionMessage("error.missing.skills");
errors.add("ActionMessages.GLOBAL_MESSAGE",error);
}

if(errors.size() > 0) {
saveErrors(request,errors);
return (new ActionForward(mapping.getInput()));
}

return (mapping.findForward("success"));

}

}
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Struts forum.
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
View source on the "blank" white page. It sounds like there is a problem with the JSP that is preventing it from rendering correcctly. The URL that you are seeing is likely correct however, as you will not see the name of the JSP in the URL.
 
Robert Bonslater
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What should I be observing when I view source for ValidatEmployee.do?
 
Robert Bonslater
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what comes up:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
<BODY></BODY></HTML>
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
90+% of the time, a blank screen means that the forward returned by the Action is not found in the ActionMapping of your struts-config.
Most everything LOOKS ok, so 1 of 2 things might be happening.
1) The error's forward is incorrect (see below)
2) Your perform method is not getting called for some reason and the default perform method in Struts sends back a null ActionForward.

Try replacing this line:
return (new ActionForward(mapping.getInput()));

with:
return mapping.getInputForward();

and we'll see what happens.

Also, it wouldn't hurt to change the name of your method from "perform" to "execute".
 
Robert Bonslater
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marc, it worked!!!

Thanks but, can you give an explanation. I replaced the perform method with execute like you said.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The perform method was deprecated in 1.1 and gone in 1.2.

In 1.1, if you overrode perform, your code still worked because execute's default implementation was to call the perform method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic