problem in my web.xml file

classic Classic list List threaded Threaded
25 messages Options
12
Reply | Threaded
Open this post in threaded view
|

problem in my web.xml file

prasanna kuppa
this is my first struts 2 application and i am getting errors plz help me out
i am using eclipse 3.4ide

my-index.jsp page:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>sample struts2 example</title>
</head>
<body>
        <s:form action="Welcome-user">
                <s:textfield name="uname" label="User Name"></s:textfield>
                <s:submit></s:submit>
        </s:form>
</body>
</html>

-------------------------------------------------------------------------------------
corresponding action file WelcomeUser.java

package com.myapp.action;

import com.opensymphony.xwork2.ActionSupport;


public class WelcomeUser extends ActionSupport
{
        private String uname;
        private String msg;
        public String execute()
        {
                msg = "welcome"+uname;
                return SUCCESS;
        }
        public String getUname() {
                return uname;
        }
        public void setUname(String uname) {
                this.uname = uname;
        }
        public String getMsg() {
                return msg;
        }
        public void setMsg(String msg) {
                this.msg = msg;
        }
       
}
------------------------------------------------------------------------------
my display page Welcome-user.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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>Insert title here</title>
</head>
<body>

${msg }

</body>
</html>
---------------------------------------------------------------------------------------
my web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  >

<display-name>Struts2Example1</display-name>
<filter>
   <filter-name>struts2</filter-name>
   <filter-class>org.apache.struts2.dispatcher.ng.filter. StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
      <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
</filter-mapping>
 
    <welcome-file-list>
       <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
 
</web-app>

it is showing following error in my web.xml file

cvc-complex-type.2.3: Element 'web-app' cannot have character [children], because the type's content type is element-only.
------------------------------------------------------------------------------------------------------in tomcat console following error message i am getting

Jun 9, 2010 7:08:56 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Java\jdk1.6.0_19\bin;C:\AppServ\Apache2.2\bin;C:\AppServ\php5;C:\Program Files\MySQL\MySQL Server 5.1\bin
Jun 9, 2010 7:08:56 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Jun 9, 2010 7:08:56 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 686 ms
Jun 9, 2010 7:08:56 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Jun 9, 2010 7:08:56 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.14
Jun 9, 2010 7:08:56 PM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter struts2
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter. StrutsPrepareAndExecuteFilter
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
        at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:249)
        at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)
        at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3696)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4343)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
        at org.apache.catalina.core.StandardService.start(StandardService.java:516)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Jun 9, 2010 7:08:56 PM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
Jun 9, 2010 7:08:56 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/struts2ex1] startup failed due to previous errors
Jun 9, 2010 7:08:56 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Jun 9, 2010 7:08:56 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Jun 9, 2010 7:08:56 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/31  config=null
Jun 9, 2010 7:08:56 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 661 ms
Jun 9, 2010 7:13:10 PM org.apache.coyote.http11.Http11Protocol pause
INFO: Pausing Coyote HTTP/1.1 on http-8080
Jun 9, 2010 7:13:11 PM org.apache.catalina.core.StandardService stop
INFO: Stopping service Catalina
Jun 9, 2010 7:13:11 PM org.apache.catalina.core.StandardContext stop
INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/struts2ex1] has not been started
Jun 9, 2010 7:13:11 PM org.apache.coyote.http11.Http11Protocol destroy
INFO: Stopping Coyote HTTP/1.1 on http-8080
 
Reply | Threaded
Open this post in threaded view
|

Re: problem in my web.xml file

vinodkashyap
Administrator
Please provide your struts.xml file

It should be in source folder
Reply | Threaded
Open this post in threaded view
|

Re: problem in my web.xml file

prasanna kuppa
i have not created any struts.xml file.i am learning struts2 from the following site

http://www.vaannila.com/struts-2/struts-2-example/struts-2-annotation-example-1.html

this the example which i was trying to execute
Reply | Threaded
Open this post in threaded view
|

Re: problem in my web.xml file

vinodkashyap
Administrator
Hey

You can visit my site.
http://javachamp.blogspot.com

There is a sample application for Struts 2:

http://javachamp.blogspot.com/2008/07/struts-2-hello-world-example.html

it is based on struts 2.0
but you can easily make it in Struts2.1 by changing libraries
Reply | Threaded
Open this post in threaded view
|

Re: problem in my web.xml file

yeahlean
Hello Vinod,

I tried to follow the steps provided in your blog and still having some problem.  Could you please help?

I'm very new to struts...


SEVERE: Exception starting filter struts2
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1361)
        at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:269)
        at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
        at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3838)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4488)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
        at org.apache.catalina.core.StandardService.start(StandardService.java:519)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Jul 26, 2010 4:12:28 PM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
Jul 26, 2010 4:12:28 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/HelloWorld] startup failed due to previous errors

=====
dir structure
HelloWorld
|---src
| |----org
| | |----vinod
| | | |----action
| | | | |----HelloWorld।java
|---struts.xml

|---WebContent
| |---jsp
| | |---HelloWorld।jsp
|---index.jsp
|---WEB-INF
| |---lib
| |---web.xml

struts.xml
========
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
        <package name="hello" extends="struts-default">
                <action name="HelloWorldAction"
                        class="org.vinod.action.HelloWorld">
                        <result>/jsp/HelloWorld.jsp</result>
                </action>
        </package>
</struts>

web.xml
======

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
        <filter>
                <filter-name>struts2</filter-name>
                <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        </filter>
        <filter-mapping>
                <filter-name>struts2</filter-name>
                <url-pattern>/*</url-pattern>
        </filter-mapping>
        <welcome-file-list>
                <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
</web-app>

Reply | Threaded
Open this post in threaded view
|

Re: problem in my web.xml file

vinodkashyap
Administrator
You must have lib in your path. Try to put the struts jar file in build path if you are using eclipse
Reply | Threaded
Open this post in threaded view
|

Re: problem in my web.xml file

Yazii
Hey ....

1. import struts.jar and xwork.jar in lib folder...

2. change the filter-class content in the web.xml to

   <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
Reply | Threaded
Open this post in threaded view
|

Re: problem in my web.xml file

Ajan
In reply to this post by prasanna kuppa
Hai prasanna,
              I know its too late reply. Anyway this will help others. There's nothing problem with the code, the thing is you need to add the jar files in to the WebContent-WEB-INF-lib folder.
 
Reply | Threaded
Open this post in threaded view
|

Re: problem in my web.xml file

Javi
I am using the same tutorial with annotations and am using maven for the libraries. The project has all libraries, but follows with the same error.
Reply | Threaded
Open this post in threaded view
|

Re: problem in my web.xml file

Md Shuphiyan
In reply to this post by Ajan
Thanks buddy !! This saved my life to..  I didn't kept jar files in lib directory. Just added jar files by selecting add external jar files.
Reply | Threaded
Open this post in threaded view
|

Re: problem in my web.xml file

shawn wu
hey guys, i am using struts-2.0.11 version, and import commons-logging-1.0.4.jar,freemarker-2.3.8.jar,ognl-2.6.11.jar,struts2-core-2.0.11.jar,xwork-2.0.4.jar to the WEB-INF\lib folder, in the web.xml file,
   <filter>
  <filter-name>struts2</filter-name>
  <filter-class>
  org.apache.struts2.dispatcher.FilterDispatcher
  </filter-class>
  </filter>
  <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping> 

when i start the tomcat 6.0.18 server, i still got the error:java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

is there anyone who can help me on this?
This problem has beset me many days, thanks very much for any help
Reply | Threaded
Open this post in threaded view
|

Re: problem in my web.xml file

Vidu12
        <filter>
                <filter-name>struts2</filter-name>
                <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        </filter>


Copy paste the above in web.xml as it is in single line. There shouldn't be any line break in <filter-class>. otherwise error will come.
Reply | Threaded
Open this post in threaded view
|

Re: problem in my web.xml file

Mohan
In reply to this post by prasanna kuppa
Hai,
I post struts2 configuration...Follow this...need to put struts2 jar files into your lib folder...Then create one source Folder rename as "resources "under src....in resources folder create struts.xml file......
The configuration is given below......



Struts-2


Step-1:    Web.xml(program starts Here)

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
        <display-name>strutssample</display-name>
        <welcome-file-list>
        <welcome-file>ss.jsp</welcome-file>  //Here you Mentioned where it will go
        </welcome-file-list>
        <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
        </filter>
        <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
        </filter-mapping>
</web-app>




Step-2:   ss.jsp(check in web.xml file and come here)

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="/struts-tags" prefix="s" %>
<!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>Registration Form</title>
</head>
<body>
<s:form action="login.action" method="post" validate="true" > //here check the action as login

        <s:textfield name="name" label="Name" />
        <s:textfield name="username"  label="User Name" />

</s:form>
</body>
</html>



Step-3: struts.xml (check the action name in jsp)


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
        <constant name="struts.enable.DynamicMethodInvocation" value="false"></constant>
        <constant name="struts.devMode" value="true" />
        <constant name="struts.custom.i18n.resources" value="ApplicationResources" />
        <package name="default" extends="struts-default">
        <result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"></result-type>
</result-types>
                <action name="login" class="pack.LoginAction">   //Here in jsp action name is login it will check then go to action class name inside the package name "pack" is "pack.LoginAction"

                        <result name="success">welcome.jsp</result> // In action class return success means execute this line...
               
                </action>
       
        </package>
</struts>



Step-4: LoginAction.java  (Action class)



package pack;

import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        private String username;
        private String password;


        public String getUsername() {
                return username;
        }

        public void setUsername(String username) {
                this.username = username;
        }

        public String getPassword() {
                return password;
        }

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

        public String execute() {
                return SUCCESS;    //Go to struts.xml check this <result name="success">welcome.jsp</result>
                }
                                       

        }

Then go to welcome.jsp


Step-5: welcome.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="/struts-tags" prefix="s" %>

<!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>
Welcome to success Page
</body>
</html>
Reply | Threaded
Open this post in threaded view
|

problem with jar

Ranjith
In reply to this post by vinodkashyap
What are the jar files required for struts2.
Reply | Threaded
Open this post in threaded view
|

problem at run time

Ranjith
In reply to this post by Mohan
hi mohan

I am getting this error how to solve it.



There is no Action mapped for namespace / and action name s. - [unknown location]
        at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:178)
        at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
        at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
        at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
        at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
        at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
        at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:306)
        at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:323)
        at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1719)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Reply | Threaded
Open this post in threaded view
|

Re: problem at run time

sakthivel
Check your struts.xml file and jsp page(View) .It says you are not  clearly defining action name either in your xml file or in jsp page.
Reply | Threaded
Open this post in threaded view
|

Re: problem at run time

Arvind kUMAR kORE
just add your struts.xml file to top of the package.
Reply | Threaded
Open this post in threaded view
|

Re: problem in my web.xml file

Struts2Newbie
In reply to this post by prasanna kuppa
Follow this steps:

1. Go to the properties of your project.
2. Select the Deployment Assembly.
3. In Web Deployment Assembly UI, press the Add button.
4. Select Java Build Path Entries and press Next.
5. Select your User Define library.
6. Done.
Reply | Threaded
Open this post in threaded view
|

problem in my web.xml file

Ashok
 
  <filter>
    <filter-name>struts2</filter-name>
      <filter-class>
         org.apache.struts2.dispatcher.FilterDispatcher
      </filter-class>
   </filter>
   <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>/*</url-pattern>
   </filter-mapping>

whenever am trying to add above code tomcat 5.5
return error messageas follows


HTTP Status 404 - /test/home.jsp
type Status report

message /test/home.jsp

description The requested resource (/test/home.jsp) is not available.


Reply | Threaded
Open this post in threaded view
|

Re: problem in my web.xml file

Harsh
In reply to this post by prasanna kuppa
Hi,

Regarding to the error mentioned
SEVERE: Exception starting filter struts2 java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

PROBLEM:
There seems to be a problem with the following combination
Eclipse - WTPPlugin - Struts2 - Maven3

FINDINGS:
We assume that when we run a project as "Run on server" we assume that eclipse runs maven, created WAR file and deploys on the server. But its not working perfectly for me. I do see the WAR file in the target folder where maven creates WAR, and the WAR is perfect. But eclipse seems to run something else.

SOLUTION:
Put all the required JAR files into eclipse project's WEB-INF/lib.
If you are using, make sure to ignore the lib folder.
How to find all the required JARs when you are using maven? Go to target folder and the WAR file. Burst it open and go to WEB-INF/lib. Copy all these JARS to eclipse project's WEB-INF/lib.

Thanks,
Harsh
12