Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

.do files are blank

 
Betsy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Kalyana Sundaram
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean it !!!

 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Betsy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic