wood burning stoves 2.0*
The moose likes Struts and the fly likes .do files are blank Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark ".do files are blank" Watch ".do files are blank" New topic
Author

.do files are blank

Betsy
Greenhorn

Joined: Jul 11, 2005
Posts: 6
i am new to struts. I have developed a simple application in which the .do file is blank.
The code is as given below.
register.jsp
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="forms"%>
<forms:form action="register">
username<forms:text property="username"/>
password<forms assword property="password1"/>
confirm password<forms assword property="password2"/>
<forms:submit value="register"/>
</forms:form>

success.jsp
<html>
<body>
Success !!
Registration Succeeded!!
</body>
</html>

struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">

<struts-config>
<form-beans>
<form-bean name="registerForm" type="app.RegisterForm"/>
</form-beans>
<action-mappings>
<action path="/register" type="app.RegisterAction" name="registerForm" scope="request" input="/register.jsp">
<forward name="success" path="/success.jsp"/>
<forward name="failure" path="/failure.jsp"/>
</action>
</action-mappings></struts-config>

web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app>
<display-name>Struts Blank Application</display-name>

<!-- Standard Action Servlet Configuration (with debugging) -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>


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


<!-- The Usual Welcome File List -->
<welcome-file-list>
<welcome-file>register.jsp</welcome-file>
</welcome-file-list>


<!-- Struts Tag Library Descriptors -->
<taglib>
<taglib-uri>/tags/struts-bean</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/tags/struts-html</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/tags/struts-logic</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/tags/struts-nested</taglib-uri>
<taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/tags/struts-tiles</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>

</web-app>

registerAction.java

// RegisterAction.java

package app;
import org.apache.struts.*;
import javax.servlet.http.*;
import java.io.*;

public class RegisterAction extends Action
{
public ActionForward perform(ActionMapping mapping,ActionForm action,HttpServletRequest req,HttpServletResponse res)
{
/*RegisterForm rf=(RegisterForm)form;
String username=rf.getUsername();
String password1=rf.getPassword1();
String password2=rf.getPassword2();
if(password1.equals(password2))
{
try
{
USerDirectory.getInstance().setUser(username,password1);
return mapping.findForward("success");*/
/*}catch(UserDirectoryException e)
{
return mapping.findForward("failure");
}
}*/
return mapping.findForward("failure");

}
}

registerForm

// RegisterForm.java

package app;
import org.apache.struts.*;
public class RegisterForm extends ActionForm
{
protected String username;
protected String password1;
protected String password2;

public String getUsername()
{
return username;
}
public String getPassword1()
{
return password1;
}
public String getPassword2()
{
return password2;
}

public void setUsername(String username)
{
this.username=username;
}
public void setPassword1(String password1)
{
this.password1=password1;
}
public void setPassword2(String password2)
{
this.password2=password2;
}
}


Please help
Kalyana Sundaram
Ranch Hand

Joined: Mar 18, 2005
Posts: 94
I think the problem is with the Taglib URI.



The uri specified in <taglib-uri> in web.xml and the uri specified in <%@ taglib> directive shopuld be same

Hope this helps


Only those who will risk going too far can possibly find out how far one can go !!!
Kalyana Sundaram
Ranch Hand

Joined: Mar 18, 2005
Posts: 94
I mean it !!!

Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
"LLL LLL",

Welcome to JavaRanch. We don't have many rules here, but we do have a naming convention which we try to strictly enforce. I believe another user has already pointed you to this document. Please re-read the naming convention and edit your display name in order to comply.

Thanks and we look forward to seeing you around the Ranch.
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
in your action class, you commented everything out and forward to 'failure' forward name which is mapped to the 'failure.jsp'. what's in there? i am betting a blank page.

also, when you decide to uncomment your codes, change the signature 'ActionForm action' to 'ActionForm form'. either the example is really bad or you're not following the example closely enough.


-/a<br />certified slacker...yes, my last name is 'do' - <a href="http://www.luckycouple.com" target="_blank" rel="nofollow">luckycouple.com</a>
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Originally posted by alan do:
in your action class, you commented everything out and forward to 'failure' forward name which is mapped to the 'failure.jsp'. what's in there? i am betting a blank page.


... oooor the failure forward is not defined in the ActionMapping (struts-config entry)


A good workman is known by his tools.
Betsy
Greenhorn

Joined: Jul 11, 2005
Posts: 6
failure.jsp

<html>
<body>
failure !!
Registration failure!!
</body>
</html>

failure.jsp is as above.
it doesnot get displayed.
Next as kalyana sundaram had pointed out, i have gone thru the tablibs also.
I dont find any difference in that.
Betsy
Greenhorn

Joined: Jul 11, 2005
Posts: 6
I have tried by changing the uri also. I didnt help.

<%@taglib uri="/tags/struts-html" prefix="forms"%>
<forms:form action="/register">
[ July 12, 2005: Message edited by: Betsy ]
Cendy Nguvy
Ranch Hand

Joined: May 25, 2005
Posts: 37
Hi,

According to java naming conventions, all the property names should start with lower letter and the firstletter of the words following should start with capital letter.

Try changing username to userName, password1 to passWord1 and password2 to passWord2 in your jsp and ActionForm and don't forget to modify getter and setter methods too.

I hope it helps you.
[ July 13, 2005: Message edited by: cendy nguvy ]
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
"Betsy",

Thanks for changing your name, but I'm afraid it still doesn't comply. Please re-read the naming convention. Specifically you must have a valid first name and a valid last name. You should be able to quickly notice that there are no users on this site with one single name. Thank you.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Originally posted by LLL LLL:
failure.jsp

<html>
<body>
failure !!
Registration failure!!
</body>
</html>

failure.jsp is as above.
it doesnot get displayed.
Next as kalyana sundaram had pointed out, i have gone thru the tablibs also.
I dont find any difference in that.


Again I say --
... oooor the failure forward is not defined in the ActionMapping (struts-config entry)
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Originally posted by cendy nguvy:
Hi,

According to java naming conventions, all the property names should start with lower letter and the firstletter of the words following should start with capital letter.

Try changing username to userName, password1 to passWord1 and password2 to passWord2 in your jsp and ActionForm and don't forget to modify getter and setter methods too.

I hope it helps you.

[ July 13, 2005: Message edited by: cendy nguvy ]


password is one word, not two.
Also, following these "conventions" does not solve the posted problem.
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
Again I say --
... oooor the failure forward is not defined in the ActionMapping (struts-config entry)


in the originally posted message shows that it is defined.
Betsy
Greenhorn

Joined: Jul 11, 2005
Posts: 6
Originally posted by Marc Peabody:


password is one word, not two.
Also, following these "conventions" does not solve the posted problem.


Yes u r right. I have tried making changes in these. But of no use.
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
"Betsy",

If you continue to not comply with our naming policy, I'm afraid I'll be forced to start closing your threads and have your account locked.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Originally posted by alan do:


in the originally posted message shows that it is defined.


Ah, yes it does.

The originally posted message also shows that the method used is perform()!
The perform method will never get called unless you are using an old version of Struts. Struts now calls the execute method which by default returns an ActionForward of null, which cannot be defined in the ActionMapping. Since the correct forward cannot be found in the ActionMapping, Struts gives you a blank page.

Change the name of the method from perform() to execute().

And it really is a good idea to give yourself a last name, Betsy.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: .do files are blank