Struts2 Hello World jsp example error

扶醉桌前 提交于 2019-12-06 11:17:07

Just add the following Jars only in the WEB-INF/lib. Remove all related jars if you don't have need.

asm-3.3.jar
asm-commons-3.3.jar
asm-tree-3.3.jar
commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
commons-lang3-3.1.jar
freemarker-2.3.19.jar
javaassist-3.11.0.GA.jar
ognl-3.0.5.jar
struts2-core-2.3.7.jar
xwork-core-2.3.7.jar

If you dont have these jars then download it.

Here org.apache.struts2.dispatcher.FilterDispatcher is now deprecated .So Edit your web.xml from

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

  <display-name>Struts 2</display-name>
  <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
  </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>

to

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Struts2 Application</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>

I guess this could do the work for you.

It seems the version of xwork-core jar that you are using is not compatible with the versions of other jars.

Try using xwork-2.1.2.jar. I have used it earlier successfully.

If it still does not work, be sure you use the same versions of each and every jar as in the sample application.

EDIT:

As per your code, try changing

public String execute() throws Exception {
  return "success";
}

to

public String execute() throws Exception {
  setName("Honey Bunny");
  return "success";
}

It seems that since you have not called the setter, Struts is searching for the property name in the session.

Regarding your question, the problem might be in the server or in your IDE tool so clean both of them under project clean and under server clean respectively.

If you face the same problem again download struts2 from this link

struts2 Just you have to copy the struts-blank.war from that folder and with the new workspace run one program (that struts-blank.war contains test programs) definitely it will work.

No classdeffound error usually comes when you haven't got that class in classpath or there are more than one versions of that class in classpath. Troubleshoot using these two options you are there. I encountered this when I was working on my JSP examples for code samples.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!