• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Configuration problem with first struts example  RSS feed

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
I am tryin my first struts application.I have a index.jsp and a mainmenu.jsp,but when
I click the index.jsp it's not showin the mainmenu.jsp or any errors instead shows a blank page.

the browser shows this:

http://localhost:8080/struts-blank/login.do;jsessionid=B305029AFC93A85875352D9AE4CA0721


Why is the login.do not goin to LoginAction and then that should forward it to mainmenu.jsp

Please help.
thanks






<?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 Bean Definitions -->

<form-beans>
<!-- Logon form bean -->

<form-bean name="loginForm"

type="LoginForm"/>


<form-bean name="userForm"

type="UserForm" />

<form-bean name="userViewForm"

type="UserViewForm" />


</form-beans>


<!-- ========================================= Global Exception Definitions -->

<global-exceptions>

</global-exceptions>


<!-- =========================================== Global Forward Definitions -->

<global-forwards>
<forward name="mainmenu" path="/mainmenu.jsp" />
<forward name="registration" path="/registration.jsp" />
<forward name="viewinfo" path="/viewinfo.jsp" />



</global-forwards>


<!-- =========================================== Action Mapping Definitions -->

<action-mappings>
<!-- Default "Welcome" action -->
<!-- Forwards to Welcome.jsp -->
<!-- Process a user logon -->

<action path="/login"

type="LoginAction"

name="loginForm"

scope="session"

input="/index.jsp">

</action>


<action path="/adduser"

type="UserAction"

name="userForm"

scope="request"

input="/adduser.jsp" />


<action path="/viewuser"

type="UserViewAction"

name="userViewForm"

scope="request"

input="/adduser.jsp" />





<!-- sample input and input submit actions

<action
path="/Input"
type="org.apache.struts.actions.ForwardAction"
parameter="/pages/Input.jsp"/>

<action
path="/InputSubmit"
type="app.InputAction"
name="inputForm"
scope="request"
validate="true"
input="/pages/Input.jsp"/>

<action
path="/edit*"
type="app.Edit{1}Action"
name="inputForm"
scope="request"
validate="true"
input="/pages/Edit{1}.jsp"/>

end samples -->
</action-mappings>


<!-- ============================================= Controller Configuration -->

<controller
processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>


<!-- ======================================== Message Resources Definitions -->

<message-resources parameter="MessageResources" />


<!-- =============================================== Plug Ins Configuration -->


<plug-in className="org.apache.struts.tiles.TilesPlugin" >

<!-- Path to XML definition file -->
<set-property property="definitions-config"
value="/WEB-INF/tiles-defs.xml" />
<!-- Set Module-awareness to true -->
<set-property property="moduleAware" value="true" />
</plug-in>


<!-- =================================================== Validator plugin -->

<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>

</struts-config>









LoginAction.java:

import java.io.IOException;

import javax.servlet.*;

import javax.servlet.http.*;

import org.apache.struts.action.*;
import java.util.*;




public class LoginAction extends Action {


public ActionForward perform(

ActionMapping mapping,

ActionForm form,

HttpServletRequest request,

HttpServletResponse response)

throws IOException, ServletException {

if(request.getSession().getServletContext().getAttribute("users") == null){

Vector users = new Vector();
request.getSession().getServletContext().setAttribute("users", users);

}


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

}





index.jsp


<%@ page language="java" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>



<html:html locale="true">

<head>

<title><bean:message key="index.title" /></title>

<html:base/>

</head>



<body>

<html:form action="/login">

<bean:message key="prompt.login" />

<html:text property="login" />

<br />

<bean:message key="prompt.password" />

<html assword property="password" />

<br />

<html:submit>

<bean:message key="index.login" />

</html:submit>

</html:form>

</body>

</html:html>





mainmenu.jsp

<%@ page language="java" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>



<html:html locale="true">

<logic:notPresent name="loginForm">

<logic:redirect href="/struts-blank/index.jsp" />

</logic:notPresent>

<logic:notPresent name="users">

<logic:redirect href="/struts-blank/index.jsp" />

</logic:notPresent>

<head>

<title><bean:message key="mainmenu.title" /></title>

<html:base/>

</head>



<body>

<html:link href="/struts-blank/adduser.jsp"><bean:message key="mainmenu.adduser" /></html:link>

<br />

<html:link href="/struts-blank/viewuser.jsp"><bean:message key="mainmenu.viewuser" /></html:link>

</body>

</html:html>




LoginForm.java:

import org.apache.struts.action.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class LoginForm extends ActionForm{

private String login;

private String password;

public String getLogin() {
return login;
}

public void setLogin(String login) {
this.login = login;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}


public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {

if (login.equals("ihurbain") && password.equals("foobar"))

return null;

else {

ActionErrors errors = new ActionErrors();

errors.add("login", new ActionError("error.login"));

return errors;

}
}


}
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!