Meaningless Drivel is fun!*
The moose likes Struts and the fly likes Struts 2 - Helloworld example from Apache site Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 - Helloworld example from Apache site" Watch "Struts 2 - Helloworld example from Apache site" New topic
Author

Struts 2 - Helloworld example from Apache site

Sam Gehouse
Ranch Hand

Joined: Jul 21, 2003
Posts: 281
New to Struts 2. Trying to run Helloworld app from Struts website:
http://struts.apache.org/2.x/docs/hello-world.html

Program compiles. All necessary jar files are in web-inf\lib. Appl server successfully started with no error and EAR file is also deployed in WebSphere test server 6.1 (inside RAD 7 IDE). But when trying to run HelloWorld.jsp from RAD, following exception stack trace is thrown in WebSphete test server:

[10/16/08 17:04:52:620 EDT] 00000010 ApplicationMg A WSVR0221I: Application started: MyS2
[10/16/08 17:06:49:043 EDT] 0000002b ServletWrappe I SRVE0242I: [MyS2] [/MyS2Web] [/HelloWorld.jsp]: Initialization successful.
[10/16/08 17:06:49:496 EDT] 0000002b ServletWrappe E SRVE0068E: Uncaught exception thrown in one of the service methods of the servlet: /HelloWorld.jsp. Exception thrown : The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
at org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:60)
at org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:52)
at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:49)
at com.ibm._jsp._HelloWorld._jspx_meth_s_property_0(_HelloWorld.java:91)
at com.ibm._jsp._HelloWorld._jspService(_HelloWorld.java:66)
at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:87)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1075)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:550)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:122)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:226)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionProcessor.handleRequest(AbstractJSPExtensionProcessor.java:285)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3391)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:267)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:811)
at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1455)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:115)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:458)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:387)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:267)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:195)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:743)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:873)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1473)
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
Try posting your web.xml file. It sounds like the filter might not be set up correctly.
Sam Gehouse
Ranch Hand

Joined: Jul 21, 2003
Posts: 281
Following is struts.xml

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="org.poc" extends="struts-default">
<action name="HelloWorld" class="org.poc.HelloWorld">
<result>/HelloWorld.jsp</result>
</action>
<!-- Add your actions here -->
</package>
</struts>
////////////////
<%@ taglib prefix="s" uri="/struts-tags" %>

<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h2><s roperty value="message" /></h2>
</body>
</html>

///////////////
Following is java class:

package org.poc;
import com.opensymphony.xwork2.ActionSupport;

public class HelloWorld extends ActionSupport {

private static final long serialVersionUID = 6393504953362012108L;
public static final String MESSAGE = "Struts is up and running ...";

public String execute() throws Exception {
setMessage(MESSAGE);
return SUCCESS;
}

private String message;

public void setMessage(String message){
this.message = message;
}

public String getMessage() {
return message;
}
}
/////////////
struts.xml is in the same directory level as that of or.poc package.
HelloWorld.jsp is rigt under WebContent directory.
Trying to run HelloWorld.jsp and getting exception being thrown resulting in page not being displayed.
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 684

Hi.

Please make sure your web xml loos like,

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" 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>Print Everywhere</display-name>

<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ActionContextCleanUp
</filter-class>
</filter>

<filter>
<filter-name>struts2</filter-name>
<filter-class>
com.printeverywhere.util.StrutsFilterDispacher
</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>
<error-page>
<error-code>404</error-code>
<location>/index.htm</location>
</error-page>

</web-app>

Thanks,
Nishan Patel.


Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
If you think your web.xml file is correct I can think of another possibility after looking at the code. When you access the screen, are you accessing it with a url like http://<myhost>:<myport>/<mycontext>/HelloWorld.jsp

or is it

http://<myhost>:<myport>/<mycontext>/HelloWorld.action

The suffixes of the URL you use for this example has to be a suffix that the struts2 filter is set up to process in the web.xml file. The standard suffix for this is .action but it can be changed, for instnace Nishan appears to have his set up to accept all suffixes. Something to take a look at if you're still having problems.
Hieu Nguyen D.
Greenhorn

Joined: Jan 04, 2010
Posts: 2
Thank you Tom. It works!
 
Consider Paul's rocket mass heater.
 
subject: Struts 2 - Helloworld example from Apache site
 
Similar Threads
Request not able to reach Action class in Struts2
PropertyNotFoundException
to Inclue jsp page in another using jsf
websphere 6.1 does not support distributed map
Exception: Cannot find bean in scope -- load testing