(Eclipse) The value for the useBean class attribute is invalid - java

I have been looking for ages now but none of the solutions google offered me helped for my situation.
I wrote a simple JSP-File and only tried to use the "useBean" statement (that's the line where the error occurs):
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%# page import="package1.TestBean" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="test" class="package1.TestBean" />
</body>
</html>
My JavaBean is an empty class but has an empty constructor without parameters:
package package1;
public class TestBean {
public TestBean() {
}
}
I created the class by right-clicking the project folder and then using New->Class.
So as I already said, the error occurs in the following line:
<jsp:useBean id="test" class="package1.TestBean" />
And the error message is (as already named in the title) "The value for the useBean class attribute package1.TestBean is invalid."
Please help me! :-(
Edit: A friend of mine tried the same, on his computer it works. Now he sent me his project folder, I imported it and it works, too!?!?!?

Solution found: There was a conflict between two Tomcat installations. See comments on Question for more detailed information.

stop Tomcat,go to Project-->Clean ->select the respective project->click clean. start Tomcat again

Related

HTTP Status 500-/index.jsp "/struts-tags" not found

Hi Can anyone help me out to resolve the error mentioned above.
I used a index.jsp file
<%# 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>
After writing all the classes and xml files,I have run the classes by tomcat server but got an error as follows
Can anyone help me out as I am new to Struts
The taglib is included in struts-core.jar, and the container will discover it automatically.
for some reason, a taglib configuration is needed within web.xml, extract the TLD file from the struts-core.jar META-INF folder, and add a taglib element to the web.xml.
<!-- ... -->
</welcome-file-list>
<taglib>
<taglib-uri>/s</taglib-uri>
<taglib-location>/WEB-INF/struts-tags.tld</taglib-location>
</taglib>
</web-app>
Try these:
Seems like you copied the libraries manually and directly into the folder WEB-INF/lib of the project and eclipse doesn't sense them, I suggest that you copy any necessary libraries into WEB-INF/lib only through eclipse. I had this issue previously and only a refresh of the project solved the problem.
add struts2-core.jar to the project
download it here.
Select Project and right click, Click on the properties, Click on
libraries tab, Click on 'Add Jars', Add relevant jar for you.

Unable to get value from value stack in struts2 using <s:action>

What I want: I want to retrieve the value from List collection.
I’m practicing/learning struts 2 framework. But, I am confused about OGNL behavior.
These are my files:
Index.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>Insert title here</title>
</head>
<body>
<hr>
<s:action name="one" />
<s:property value="list_fruits[0]" />
</body>
</html>
MyAction.java
package abc;
import java.util.*;
import org.apache.struts2.dispatcher.RequestMap;
import com.opensymphony.xwork2.*;
public class MyAction extends ActionSupport {
private List list_fruits;
public List getList_fruits() {
return list_fruits;
}
public void setList_fruits(List list_fruits) {
this.list_fruits = list_fruits;
}
public String doOne() {
list_fruits = new ArrayList();
list_fruits.add("banana");
list_fruits.add("apple");
list_fruits.add("mango");
/*RequestMap rm = (RequestMap) ActionContext.getContext().get("request");
rm.put("req_scope", list_fruits);*/
return "sendToOne";
}
}
one.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>Insert title here</title>
</head>
<body>
<h1>ONE.JSP</h1>
<br>
<s:property value="list_fruits[0]" />
</body>
</html>
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="devMode" value="true" />
<package name="vns" extends="struts-default">
<action name="one" class="abc.MyAction" method="doOne">
<result name="sendToOne">/one.jsp</result>
</action>
</package>
</struts>
I am experiencing following behaviors:
Case1: When I put this (below) code in index.jsp, I get NO value printed.
<s:action name="one"/>
<s:property value="list_fruits[0]"/>
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Case2: When I put this (below) code in index.jsp, the value gets printed from one.jsp because in this scene I included attribute executeResult=”true”
<s:action name="one" executeResult="true"/>
<s:property value="list_fruits[0]"/> <!-- still NOT printed here, but gets printed from one.jsp -->
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Case3: When I put this (below) code in MyAction.java and index.jsp, then the value get printed on screen (index.jsp).
MyAction.java
RequestMap rm=(RequestMap)ActionContext.getContext().get("request");
rm.put("req_scope", list_fruits);
index.jsp
<s:action name="one"/> <!-- removed executeResult="true" -->
<s:property value="#request.req_scope[0]"/>
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
in Case2 value gets printed due to one.jsp and not due to index.jsp
I want to know why I am NOT getting any value printed in Case1 whereas in Case2 and Case3, there is no such problem. Why is it so? Can anyone guide me?
AleksandrM already answered you, but since you said
still not clear. :( please explain.
You can use it for :
calling an Action and use executeResult="true" to get the result;
calling an Action and push it on the main page ValueStack with var attribute, then reference it with # :
<s:action name="one" var="instance" />
<s:property value="#instance.list_fruits[0]"/>
calling an Action that sets something in request / session scope, and then retrieve those values by using #attr or #session;
calling an Action that does something (e.g. persists into the database the timestamp of when the page has been opened).
But you can do any of this single things server side, and BETTER.
This is why you shouldn't use the <s:action/> tag: it breaks most of the S2 framework conventions and mechanisms and it is a bad practice (or at least it isn't a good one).

struts2 mysql conection error in eclipse

I am connecting to MySQL using JDBC to the JSP, but it shows error classNotFoundException in eclipse in struts JSP page.
validate.java:
package com.demo;
import java.sql.*;
public class LoginValidate {
public boolean validateLogin(){
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/inspioqj_appointment");
return true;
}
}
Same code using in same project jsp file its working what is problem i am not understanding.
index.jsp:
<%# page language="java" import="java.sql.*" 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>
<p> There is home page.</p>
<hr/>
login|
logout|
profile
<%
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/inspioqj_appointment");
%>
</body>
</html>
I have included MySQL java connector on lib folder in eclipse struts project, but it is not working in action controller validate.java but it is working in index.jsp page.
What is problem? I could not understand.
Its a pretty simple ClassNotFoundException. Make sure that the mySQL jar is present in the class-path of the project as well. You can do this by right-clicking the project, configure class-path and from there you can add the particular jar

Applet Class Not Found Error

i have just started learning jsp, i came across running Applet from jsp, the code below doesn't seems to work.
<%# 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>InfoVisual</title>
</head>
<body>
<jsp:plugin type="applet" codebase="WEB-INF/classes" code="DemoApplet.class" width="400" height="400">
<jsp:fallback>
<p>Unable to load applet</p>
</jsp:fallback>
</jsp:plugin>
<input name="btnShow" value="Show" type="submit">
</body>
</html>
My eclipse project structure is like below
I don't know why i can't see the applet running.
Have i placed files in right folders???
Classes in WEB-INF/classes are only visible to server-side code such as servlets. Instead create a JAR file containing the compiled classes required to run the applet are place them in the same location as the JSP file. The plugin tag will then look like
<jsp:plugin type="applet" code="DemoApplet.class" archive="MyAppletJar.jar" width="400" height="400">
<jsp:fallback>
<p>Unable to load applet</p>
</jsp:fallback>
</jsp:plugin>
this code worked perfectly:
<applet code="DemoApplet.class" name="DemoApplet" archive="DemoApplet.jar" width=300 height=300>
</applet>
and here is my project structure:
Thanx for the help :))

Package Beans does not Exist

I am a .NET developer dabbling into the JSP world. I loaded NetBeans 6.5.1 and get an error in this page:
<%#page import="java.io" %>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"w3.org/TR/html4/loose.dtd">;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
the error is:
"Package Beans does not Exist"
I should add that I created a new Java Web Application and then copy-and-pasted some code that called for the above import. then I get the error.
Help with this error would be great along with any tutorials or books.
Something is wrong with the classpath. Your configuration of the server, plus setup in the WAR file, should be checked against a working one.

Categories