I believe WL 7 is servlet 2.3 compliant so you don't have to copy the tlds into WEB-INF. See the users guide for more details that will make your deployment easier.

David






From: Suman Das <[EMAIL PROTECTED]>
Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Subject: ActionServlet unable to proceed...pl help
Date: Sun, 17 Nov 2002 01:54:04 -0800 (PST)


Hi!
While running the following code (more or less same as Javaranch's march article) in weblogic 7.0, the LoginView.jsp accepts UserID and Pwd but then 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:password 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





---------------------------------
Do you Yahoo!?
Yahoo! Web Hosting - Let the expert host your site

_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail


--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to