my welcome page is welcome.jsp
listed in web.xml
file
welcome.jsp
contains a simple form for submission to an action which is mapped by struts-config.xml
file
all the mappings are correct as the form goes for submission to an action a blank page is displayed by the browser? I don't know what's the problem.
the address bar shows the correct URL which is hitting the correct action but still blank page is displayed.
I am providing my welcome.jsp
, struts-config.xml
file , action here in the snippet
struts-config.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans>
<form-bean name="login1" type="aditya.bean.LoginBean"/>
</form-beans>
<!-- <global-forwards>
</global-forwards>-->
<!-- Action Mappings -->
<action-mappings>
<action path="/login"
type="aditya.action.LoginAction"
name="login1"
parameter="method"
/>
<forward name="loginadmin" path="/jsp/adminwel.jsp" />
<forward name="loginuser" path="tuser"/>
</action-mappings>
<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>
<!-- <message-resources parameter="ApplicationResources" null="false" /> -->
<plug-in className="org.apache.struts.tiles.TilesPlugin">
<set-property property="definitions-config" value="/WEB-INF/tiles-def.xml"/>
<set-property property="moduleAware" value="true"/>
</plug-in>
</struts-config>
welcome.jsp
:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="h" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome</title>
</head>
<body>
<h:form action="login.do" method="post">
<table border="5" bgcolor="cyan" align="center">
<tr><td>USER ID</td><td><h:text property="uid"/></td></tr>
<tr><td>PASSWORD</td><td><h:password property="pass"/></td></tr>
<tr><td><h:submit property="method" value="login"/></td></tr>
</table>
</h:form>
</body>
</html>
LoginAction
:
package aditya.action;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import aditya.bean.LoginBean;
public class LoginAction extends DispatchAction {
public ActionForward login(ActionMapping mapping,ActionForm form,HttpServletRequest req,HttpServletResponse res)throws ServletException
{
LoginBean loginBean=(LoginBean)form;
System.out.println("in action-");
if(loginBean.getUid().equalsIgnoreCase("admin")&&loginBean.getPass().equalsIgnoreCase("admin"))
{
return mapping.findForward("loginadmin");
}
else
{
return mapping.findForward("loginuser");
}
}
}
Why the browser is displaying a blank webpage?
IDE Used --> Eclipse
The blank page is displayed because none of the results returned to the browser from the action class. In the login()
action the code should return ActionForward
instance. But it returns null
.
Define global forwards:
<global-forwards>
<forward name="error" path="/error.jsp"/>
</global-forwards>
Action code:
ActionForward result;
if(loginBean.getUid().equalsIgnoreCase("admin")&&loginBean.getPass().equalsIgnoreCase("admin"))
{
result = mapping.findForward("loginadmin");
if (result == null)
return mapping.findForward("error");
}
else {
result = mapping.findForward("loginuser");
if (result == null)
return mapping.findForward("error");
}
return result;