This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts application showing requested resource is not available

 
pihu blank
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I just made my first struts application which is a simple Login App but I am unable to run it. I am using Tomcat 6. It will be great if someone can help me with this

The error I recieve when I open "http://localhost:8080/StrutsLogin/" is as follow :
description- The requested resource (/StrutsLogin/) is not available.

Below is the code I wrote.

1)LoginAction

package com.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.struts.form.LoginForm;;

public final class LoginAction extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

LoginForm loginForm = (LoginForm) form;

// validating login
if (loginForm.getUname().equals("abc")
&& loginForm.getPwd().equals("abc")) {
return mapping.findForward("admin");
} else if (loginForm.getUname().equals("sdf")
&& loginForm.getPwd().equals("sdf")) {
return mapping.findForward("visitor");
} else {
return mapping.findForward("error");
}

}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

2)LoginForm

package com.struts.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class LoginForm extends ActionForm {

private static final long serialVersionUID = 1L;
private String uname = "";
private String pwd = "";

public void setUname(String uname) {
this.uname = uname;
}

public String getUname() {

return uname;
}

public void setPwd(String pwd) {
this.pwd = pwd;
}

public String getPwd() {

return pwd;
}

// validating form errors
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {

ActionErrors errors = new ActionErrors();

if (uname == null || uname == "") {
errors.add("uname", new ActionError("error.uname.required"));
}

if (pwd == null || pwd == "") {
errors.add("pwd", new ActionError("error.pwd.required"));
}

return errors;

}
}

---------------------------------------------------------------------------------------------------------------------------------------------------------
3)struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<form-beans>
<form-bean name="LoginForm" type="com.struts.form">
</form-bean>
</form-beans>

<action-mappings>
<action input="/login.jsp" type="com.struts.action" name="LoginForm" path="login" scope="request" validate="true">
<forward name="admin" path="/admin.jsp"/>
<forward name="visitor" path="/visitor.jsp"/>
<forward name="error" path="/error.jsp"/>
</action>
</action-mappings>

</struts-config>


------------------------------------------------------------------------------------------------------------------------------------

4)web.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app >
<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>
</servlet>



<welcome-file-list>
<welcome-file>/login.jsp</welcome-file>
</welcome-file-list>


<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
</web-app>
-----------------------------------------------------------

5) login.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Login Page</title>
</head>
<body bgcolor="#f6f7f8">
<center>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<html:errors/>

<html:form action="/login">
<table>
<tr>
<td align="right">Username:</td>
<td><html:text name="LoginForm" property="uname"/></td>
</tr>
<tr />
<tr>
<td align="right">Password:</td>
<td><html:password name="LoginForm" property="pwd"/></td>
</tr>
<tr>
<td><html:submit value="Login"/></td>
<td><html:reset value="Reset"/></td>
</tr>
</table>
</html:form>
</center>
</body>
</html>

------------------------------------------------------------------------------------------------

The Console shows the following message :

Oct 12, 2013 12:40:35 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_16\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jdk1.6.0_16/bin/../jre/bin/client;C:/Program Files/Java/jdk1.6.0_16/bin/../jre/bin;C:/Program Files/Java/jdk1.6.0_16/bin/../jre/lib/i386;C:\Program Files\RSA SecurID Token Common;C:\Program Files\Java\jdk1.6.0_16\bin;C:\ORACLE\product\10.2.0\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Windows Imaging\;C:\eclipse;
Oct 12, 2013 12:40:35 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:NewLogin' did not find a matching property.
Oct 12, 2013 12:40:35 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:StrutsLogin' did not find a matching property.
Oct 12, 2013 12:40:35 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Oct 12, 2013 12:40:35 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 490 ms
Oct 12, 2013 12:40:35 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Oct 12, 2013 12:40:35 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.32
Oct 12, 2013 12:40:36 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(C:\New-Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\NewLogin\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
Oct 12, 2013 12:40:36 PM org.apache.catalina.startup.TldConfig lifecycleEvent
SEVERE: Error processing TLD files for context path /StrutsLogin
javax.servlet.ServletException: Exception processing TLD at resource path /WEB-INF/struts-html.tld in context /StrutsLogin
at org.apache.catalina.startup.TldConfig.tldScanTld(TldConfig.java:438)
at org.apache.catalina.startup.TldConfig.execute(TldConfig.java:267)
at org.apache.catalina.startup.TldConfig.lifecycleEvent(TldConfig.java:634)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4611)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.IllegalArgumentException: Invalid TLD resource path /WEB-INF/struts-html.tld
at org.apache.catalina.startup.TldConfig.tldScanTld(TldConfig.java:426)
... 17 more
Oct 12, 2013 12:40:36 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Oct 12, 2013 12:40:36 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Oct 12, 2013 12:40:36 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/32 config=null
Oct 12, 2013 12:40:36 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 733 ms

TIA

 
pihu blank
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
made some changes in these...although I was able to run the code for sometime..after trying of lots of things..after some time still back to this..Arghhh!!..
don't know what changed in between

struts-config

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<form-beans>
<form-bean name="LoginForm" type="com.struts.form.LoginForm"/>
</form-beans>


<action-mappings>
<action input="/login.jsp" type="com.struts.action.LoginAction" name="LoginForm" path="/login" scope="request" validate="true">
<forward name="admin" path="/admin.jsp"/>
<forward name="visitor" path="/visitor.jsp"/>
<forward name="error" path="/error.jsp"/>
</action>
</action-mappings>



--------------------------------------------------------------------------

and web.xml
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app >
<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>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>

-------------------------------------------------------------------------------------------------------

login.jsp


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Login Page</title>
</head>
<body bgcolor="#f6f7f8">
<center>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<html:errors/>

<html:form action="login">
<table>
<tr>
<td align="right">Username:</td>
<td><html:text name="LoginForm" property="uname"/></td>
</tr>
<tr />
<tr>
<td align="right">Password:</td>
<td><html:password name="LoginForm" property="pwd"/></td>
</tr>
<tr>
<td><html:submit value="Login"/></td>
<td><html:reset value="Reset"/></td>
</tr>
</table>
</html:form>
</center>
</body>
</html>











<welcome-file-list>
<welcome-file>/login.jsp</welcome-file>
</welcome-file-list>


<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
</web-app>



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic