Megha S
asked on
After logging with name, error 500 message is displayed
Receiving error as follows. Please do needful.
HTTP Status 500 - Filter execution threw an exception
exception :
javax.servlet.ServletExcep tion: Filter execution threw an exception
root cause :
java.lang.Error: Unresolved compilation problems:
The import com.opensymphony cannot be resolved
The import com.opensymphony cannot be resolved
The import com.opensymphony cannot be resolved
ActionSupport cannot be resolved to a type
ValueStack cannot be resolved to a type
ActionContext cannot be resolved
com.tutorialspoint.struts2 .HelloWorl dAction.<i nit>(Hello WorldActio n.java:5)
sun.reflect.NativeConstruc torAccesso rImpl.newI nstance0(N ative Method)
sun.reflect.NativeConstruc torAccesso rImpl.newI nstance(Un known Source)
sun.reflect.DelegatingCons tructorAcc essorImpl. newInstanc e(Unknown Source)
java.lang.reflect.Construc tor.newIns tance(Unkn own Source)
java.lang.Class.newInstanc e(Unknown Source)
com.opensymphony.xwork2.Ob jectFactor y.buildBea n(ObjectFa ctory.java :130)
com.opensymphony.xwork2.Ob jectFactor y.buildBea n(ObjectFa ctory.java :161)
com.opensymphony.xwork2.Ob jectFactor y.buildBea n(ObjectFa ctory.java :150)
com.opensymphony.xwork2.Ob jectFactor y.buildAct ion(Object Factory.ja va:120)
com.opensymphony.xwork2.De faultActio nInvocatio n.createAc tion(Defau ltActionIn vocation.j ava:300)
com.opensymphony.xwork2.De faultActio nInvocatio n.init(Def aultAction Invocation .java:400)
com.opensymphony.xwork2.De faultActio nProxy.pre pare(Defau ltActionPr oxy.java:1 94)
org.apache.struts2.impl.St rutsAction Proxy.prep are(Struts ActionProx y.java:63)
org.apache.struts2.impl.St rutsAction ProxyFacto ry.createA ctionProxy (StrutsAct ionProxyFa ctory.java :39)
com.opensymphony.xwork2.De faultActio nProxyFact ory.create ActionProx y(DefaultA ctionProxy Factory.ja va:58)
org.apache.struts2.dispatc her.Dispat cher.servi ceAction(D ispatcher. java:500)
org.apache.struts2.dispatc her.Filter Dispatcher .doFilter( FilterDisp atcher.jav a:434)
My code as follows :
HelloWorld.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"% >
<%@ taglib prefix = "s" uri = "/struts-tags" %>
<!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>Hello World</title>
</head>
<body>
Entered value : <s:property value = "name"/><br/>
Value of key 1 : <s:property value = "key1" /><br/>
Value of key 2 : <s:property value = "key2" /> <br/>
</body>
</html>
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"% >
<%@ taglib prefix = "s" uri = "/struts-tags"%>
<!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>Hello World</title>
</head>
<body>
<h1>Hello World From Struts2</h1>
<form action = "hello">
<label for = "name">Please enter your name</label><br/>
<input type = "text" name = "name"/>
<input type = "submit" value = "Say Hello"/>
</form>
</body>
</html>
HelloWorldAction.java
package com.tutorialspoint.struts2 ;
import java.util.*;
import com.opensymphony.xwork2.ut il.ValueSt ack;
import com.opensymphony.xwork2.Ac tionContex t;
import com.opensymphony.xwork2.Ac tionSuppor t;
public class HelloWorldAction extends ActionSupport {
private String name;
public String execute() throws Exception {
ValueStack stack = ActionContext.getContext() .getValueS tack();
Map<String, Object> context = new HashMap<String, Object>();
context.put("key1", new String("This is key1"));
context.put("key2", new String("This is key2"));
stack.push(context);
System.out.println("Size of the valueStack: " + stack.size());
return "success";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
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>
<constant name = "struts.devMode" value = "true" />
<package name = "helloworld" extends = "struts-default">
<action name = "hello"
class = "com.tutorialspoint.struts 2.HelloWor ldAction"
method = "execute">
<result name = "success">/HelloWorld.jsp< /result>
</action>
</package>
</struts>
web.xml
<?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" 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>Ognlvaluesta ck</displa y-name>
<welcome-file-list>
<welcome-file>index.jsp</w elcome-fil e>
</welcome-file-list>
<filter>
<filter-name>struts2</filt er-name>
<filter-class>
org.apache.struts2.dispatc her.Filter Dispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filt er-name>
<url-pattern>/*</url-patte rn>
</filter-mapping>
</web-app>
HTTP Status 500 - Filter execution threw an exception
exception :
javax.servlet.ServletExcep
root cause :
java.lang.Error: Unresolved compilation problems:
The import com.opensymphony cannot be resolved
The import com.opensymphony cannot be resolved
The import com.opensymphony cannot be resolved
ActionSupport cannot be resolved to a type
ValueStack cannot be resolved to a type
ActionContext cannot be resolved
com.tutorialspoint.struts2
sun.reflect.NativeConstruc
sun.reflect.NativeConstruc
sun.reflect.DelegatingCons
java.lang.reflect.Construc
java.lang.Class.newInstanc
com.opensymphony.xwork2.Ob
com.opensymphony.xwork2.Ob
com.opensymphony.xwork2.Ob
com.opensymphony.xwork2.Ob
com.opensymphony.xwork2.De
com.opensymphony.xwork2.De
com.opensymphony.xwork2.De
org.apache.struts2.impl.St
org.apache.struts2.impl.St
com.opensymphony.xwork2.De
org.apache.struts2.dispatc
org.apache.struts2.dispatc
My code as follows :
HelloWorld.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%
<%@ taglib prefix = "s" uri = "/struts-tags" %>
<!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>Hello World</title>
</head>
<body>
Entered value : <s:property value = "name"/><br/>
Value of key 1 : <s:property value = "key1" /><br/>
Value of key 2 : <s:property value = "key2" /> <br/>
</body>
</html>
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%
<%@ taglib prefix = "s" uri = "/struts-tags"%>
<!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>Hello World</title>
</head>
<body>
<h1>Hello World From Struts2</h1>
<form action = "hello">
<label for = "name">Please enter your name</label><br/>
<input type = "text" name = "name"/>
<input type = "submit" value = "Say Hello"/>
</form>
</body>
</html>
HelloWorldAction.java
package com.tutorialspoint.struts2
import java.util.*;
import com.opensymphony.xwork2.ut
import com.opensymphony.xwork2.Ac
import com.opensymphony.xwork2.Ac
public class HelloWorldAction extends ActionSupport {
private String name;
public String execute() throws Exception {
ValueStack stack = ActionContext.getContext()
Map<String, Object> context = new HashMap<String, Object>();
context.put("key1", new String("This is key1"));
context.put("key2", new String("This is key2"));
stack.push(context);
System.out.println("Size of the valueStack: " + stack.size());
return "success";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
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>
<constant name = "struts.devMode" value = "true" />
<package name = "helloworld" extends = "struts-default">
<action name = "hello"
class = "com.tutorialspoint.struts
method = "execute">
<result name = "success">/HelloWorld.jsp<
</action>
</package>
</struts>
web.xml
<?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" 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>Ognlvaluesta
<welcome-file-list>
<welcome-file>index.jsp</w
</welcome-file-list>
<filter>
<filter-name>struts2</filt
<filter-class>
org.apache.struts2.dispatc
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filt
<url-pattern>/*</url-patte
</filter-mapping>
</web-app>
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.