Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help - cannot find resource welcome.do

 
Avneet Singh
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I have gone thru few examples of struts application but once i start making my own application it cannot find the action. the exact error is :-

The requested resource (/welcome.do) is not available.

Im pasting below the files struts-config.xml and web.xml and my jsp files

any help is appreciated , i just cant figure out why it cant find the action requested it works fine in examples if i try to overide those examples .

below are the files -

struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>

<!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-beans>
<global-forwards >
</global-forwards>
<action-mappings>
<action path="/welcome"
type="myappcls.FrmBeanAction">
<forward name="success"
path="welcome.jsp"/>
</action>

</action-mappings>

</struts-config>

web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Copyright 2004 The Apache Software Foundation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<!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>

<display-name>Avneet</display-name>
<description>
Struts implimentation
</description>
<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>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<taglib>
<taglib-uri>/tags/taglib/struts-bean</taglib-uri>
<taglib-location>/WEB-INF/taglib/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/taglib/struts-html</taglib-uri>
<taglib-location>/WEB-INF/taglib/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/taglib/struts-logic</taglib-uri>
<taglib-location>/WEB-INF/taglib/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/taglib/struts-nested</taglib-uri>
<taglib-location>/WEB-INF/taglib/struts-nested.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/taglib/struts-tiles</taglib-uri>
<taglib-location>/WEB-INF/taglib/struts-tiles.tld</taglib-location>
</taglib>
</web-app>

jsp files are below -

index.jsp

<%@ page language="java" %>
<%
System.out.println("inside index.jsp");
%>
<HTML>
<HEAD><TITLE>New Account Registration</TITLE></HEAD>
<BODY BGCOLOR="#FDF5E6">
<CENTER>
<H1>New Account Registration</H1>
<FORM ACTION="/welcome.do" METHOD="POST">
Email address: <INPUT TYPE="TEXT" NAME="email"><BR>
Password: <INPUT TYPE="PASSWORD" NAME="password"><BR>
<INPUT TYPE="SUBMIT" VALUE="Sign Me Up!">
</FORM>
</CENTER>
</BODY></HTML>

welcome.jsp ->
<%@page language="java" %>
<HTML>
<HEAD><TITLE>Success</TITLE></HEAD>
<BODY BGCOLOR="#FDF5E6">
<CENTER>
<H1>You have registered successfully.</H1>
(Version 1)
</CENTER>
</BODY></HTML>


Action class ->

package myappcls ;

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

public class FrmBeanAction extends Action{
public ActionForward execute(ActionMapping mapping , ActionForm action , HttpServletRequest request , HttpServletResponse response) throws Exception{
System.out.println("Inside control Servlet -> FrmBeanAction");
return mapping.findForward("success");

}
}

action bean ->

package myappcls ;
import org.apache.struts.action.*;
public class FrmBean extends ActionForm{

private String name = "" ;


public void setName(String name){
this.name = name ;
}

public String getName(){
return this.name ;
}


}

now when i open index and do submit it cannot go to my action servlet and gives the message listed above .

need help

Thanks to all in advance
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you see any exception stacktrace on your server console or server log. If yes, post the exception stacktrace
 
Avneet Singh
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No there is no stach trace of the error the jsp page shows just
cannot find resource welcome.do

the server catalina doesnt give any errors basically it cannot find my action servlet as i think because it doesnt print the System.out.println lines that i have in there .

Can u run this small ap on ur server and check if it wrks on urs.

I just cant figure out why, all the examples seem to run fine. even if i edit them.
Thanks avneet
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can u run this small ap on ur server and check if it wrks on urs

Give me some time. Let me try.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried it, did some changes and here are the working files:

index.jsp:



Changes: 1) Used html:form instead of form(also added the @taglib directive)
2) Also, placed struts-html.tld file in WEB-INF directory.

struts-config.xml:



Changes: 1) In the action tag, changed path="welcome.jsp" to path="/welcome.jsp"
2) Added the form-bean declaration and used the same in the action tag

All the other files remain unchanged
[ July 13, 2006: Message edited by: jaikiran pai ]
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The exact reason why you were seeing the mapping not found error, was because in index.jsp:

<FORM ACTION="/welcome.do"

you were *not* specifying the context of the application.
So i changed the <form> tag to <html:form> tag which by default prefixes the context of the application to the action url.

If you do not want to use the <html:form> tag then you can change the index.jsp to:


assuming, myApp is the context-root of your application.
 
Avneet Singh
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks jaikiran for ur help il do these changes

thanks alot man
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic