Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what does .do file extension indicate

 
Suman Dass
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what does .do file extension indicate; e.g. login.do
 
Jose Velarde
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's just a servlet mapping defined in the deployment descriptor (web.xml).

The container will pass to the Action Servlet any request that matches the pattern. However, any valid prefix or extension can be used. Developers just use .do since it's more popular.
[ November 16, 2002: Message edited by: Jose Velarde ]
 
Suman Dass
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thnx jose! actually i was trying to run the progarm given in javaranch's struts topic. i'm using weblogic 7.0. while LoginView.jsp is working, on submission, it calls login.do after which it goes blank, i.e. ActionServlet doesnt seem to get called. The directory structure of Weblogic is slightly different than Tomcat.
 
Jose Velarde
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the struts-config.xml. You probably are missing some entries there.
 
Suman Dass
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
unfortunately i still couldnt resolve the problem.....the login.do returns a blank page...seems ActionServlet is unable to proceed. Here's my directory structure (weblogic 7.0) and the source codes (more or less same as March article). Pl help.

examplesWebApp
|_WEB-INF
||_______classes
||_______lib |___test
|struts-config.xml |__struts
|web.xml LoginAction.class
| LoginBean.class
MainMenu.jsp LoginForm.class
LoginView.jsp MessageResource.props

The files are as under:
<!-- LoginView.jsp -->
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts.tld" prefix="struts" %>
<HTML>
<HEAD><TITLE><struts:message key="title.login" /></TITLE></HEAD>
<BODY>
<struts:message key="heading.login" />
<html:errors />
<html:form action="/login">
<p>
<struts:message key="label.userId" />:
<html:text property="userId" size="10" />
<br>
<struts:message key="label.passWord" />:
<html assword property="passWord" size="10" />
<br><br>
<html:submit>
<bean:message key="button.submit" />
</html:submit>
</html:form>
</BODY>
</HTML>
******************************************************
File:struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
<struts-config>
<!-- ========== Form Bean Definitions ============ -->
<form-beans>
<form-bean name="login" type="test.struts.LoginForm" />
</form-beans>

<!-- ========== Global Forward Definitions ========= -->
<global-forwards>
</global-forwards>

<!-- ========== Action Mapping Definitions ======== -->
<action-mappings>
<action
path="/login"
type="test.struts.LoginAction"
scope="request"
name="login"
input="LoginView.jsp"
validate="true">
<forward name="valid" path="MainMenu.jsp" redirect="true"/>
<forward name="invalid" path="LoginView.jsp" redirect="true"/>
</action>
</action-mappings>
</struts-config>
**********************************************
<!-- MainMenu.jsp -->
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts.tld" prefix="struts" %>
<jsp:useBean id="LoginBean" scope="request" class="test.struts.LoginBean" />
<HTML>
<HEAD><TITLE><struts:message key="title.mainmenu" /></TITLE></HEAD>
<BODY>
<struts:message key="heading.mainmenu" />
<p>
<struts:message key="label.userType" />:
<b><jsp:getProperty name="LoginBean" property="userType" /></b><br>
</BODY>
</HTML>
**********************************************
File: web.xml
<web-app>
<display-name>Examples Web Application</display-name>
<!-- Action Servlet Configuration -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>application</param-name>
<param-value>test.struts.MessageResources</param-value>
</init-param>
<init-param>
<param-name>mapping</param-name>
<param-value>org.apache.struts.action.RequestActionMapping</param-value>
</init-param>
<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>
<load-on-startup>2</load-on-startup>
</servlet>

<!-- Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- Struts Tag Library Descriptors -->
<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-template.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-template.tld</taglib-location>
</taglib>
</web-app>
*************************************************
package test.struts;
import javax.servlet.http.*;
import org.apache.struts.action.*;
public class LoginAction extends Action {
public LoginAction() {}
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, javax.servlet.ServletException{
LoginBean lb = new LoginBean();
request.setAttribute("LoginBean", lb);
lb.setParameters(request);
ActionErrors ae = lb.validate();
request.setAttribute(Action.ERROR_KEY, ae);
if (ae == null || ae.size() == 0) {
System.out.println("after LoginAction");
return mapping.findForward("valid");
} else {
return mapping.findForward("invalid");
}
}
}
*****************************
package test.struts;
import org.apache.struts.action.*;
import javax.servlet.http.*;
public class LoginForm extends ActionForm {
String userId, passWord;
public void setUserId(String userId) {
this.userId = userId;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
public String getUserId() {
return userId;
}
public String getPassWord() {
return passWord;
}
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors ae = new ActionErrors();
if (userId == null || userId.equals("")) {
ae.add("userId", new ActionError("error.no.userId"));
}
if (passWord == null || passWord.equals("")) {
ae.add("passWord", new ActionError("error.no.passWord"));
}
return ae;
}
}
******************************************
package test.struts;
import javax.servlet.http.*;
import org.apache.struts.action.*;
public class LoginBean {
String userType, userId ,passWord;
public LoginBean() {}
public void setParameters(HttpServletRequest request) {
String userId = request.getParameter("userId");
String passWord = request.getParameter("passWord");
}
public ActionErrors validate() {
if (!userId.equals(passWord)) {
ActionErrors ae = new ActionErrors();
ae.add("userId", new ActionError("error.invalid.login"));
return ae;
}
if (userId.equals("admin")) {
userType = "Adminstrator";
} else
if (userId.equals("user")) {
userType = "User";
} else {
ActionErrors ae = new ActionErrors();
ae.add("userId", new ActionError("error.invalid.login"));
return ae;
}
return null;
}
public String getUserType() {
return userType;
}
public void setUserType(String userType) {
this.userType = userType;
}
}
*****************************************
File: MessageResources.properties
title.login=Login
button.submit=Send for Verification
error.no.userId=<li>User ID is a required field</li>
error.no.passWord=<li>Password is a required field</li>
error.invalid.login=<li>The User ID and/or Password are invalid. Please try again.</li>
errors.footer=</ul><hr>
errors.header=<h3><font color="red">Validation Error</font></h3>You must correct the following error(s) before proceeding:<ul>
label.userId=User ID
label.passWord=Password
heading.login=<H2>Enter your user information</H2>
heading.mainmenu=<H1>Welcome!</H1>
label.userType=<H2>You are authorized to use this system as a</H2>
title.mainmenu=Title
 
Suman Dass
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my directory structure once again:
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Suman,
to try to work out what error you are getting, do some or all of the following:
- check the weblogic log files for exceptions
- put logging to the console in your action's perform or execute
- put logging in your form bean's reset() and validate() methods
- log which forward you return from your perform/execute() in the action
Also I don't recognise the "redirect" attribute on the forwards you declare in your action mapping for the login.do - do you know what it does? Otherwise get rid of it for now.
This should get you more info that should point to what you need to do.
 
Alexander Klimuk
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why have you removed slashes?
E.g. you have following line in Action Mapping:
<forward name="valid" path="MainMenu.jsp" redirect="true"/>
Normally, path should be specified like path="/MainMenu.jsp"
The same about "LoginView.jsp".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic