Package Beans does not Exist - java

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.

Related

javax.el.ExpressionFactory.newInstance() not found on Jetty and Java 7

I have this JSP:
<%# page pageEncoding="UTF-8" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="contextPath" value="http://localhost:8000/"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<link type="text/css" rel="stylesheet" href="${contextPath}/css/styles.css"/>
</head>
<body>
<!-- some html -->
</body>
When I navigate to this page, I get next error:
java.lang.NoSuchMethodError: javax.el.ExpressionFactory.newInstance()Ljavax/el/ExpressionFactory;
at org.apache.jasper.compiler.JspUtil.getExpressionFactory(JspUtil.java:1182)
at org.apache.jasper.compiler.JspUtil.validateExpressions(JspUtil.java:644)
at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:752)
at org.apache.jasper.compiler.Node$ELExpression.accept(Node.java:946)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2291)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2341)
at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2347)
at org.apache.jasper.compiler.Node$Root.accept(Node.java:498)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2291)
[...]
The environment to execute this page is Java 7 and Jetty.
If I remove ${contextPath} works fine.
Why i have this error?
Best regards
The cause of your error is 2 different EL language jars in your classpath.
EL version 2.1 is what is actively being used by your webapp, and is the cause of your error (that method doesn't exist in EL 2.1)
EL version 2.2 is what your webapp needs to be using for javax.el.ExpressionFactory.newInstance(), as that method was introduced in EL 2.2
Make sure you are using the correct version of the EL lib, and that you don't have multiple versions of it present in your webapp
Also, why not just use ...
<link type="text/css" rel="stylesheet"
href="${pageContext.request.contextPath}/css/styles.css"/>
and skip the whole <c:set> you are using? (your choice of a fully qualified URI is a bad idea anyway)

Offline cache using manifest appcache

I am trying to make my application offline enabled.
This is my starting page of the app which I have put on TOMCAT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html manifest="test.appcache">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
Hello World
</body>
</html>
And Here is my test.appcache (although I am not using any of the files mentioned in my manifest files at this point - its just a POC)
CACHE MANIFEST
#version 821
CACHE:
test.html
/resources/test.js
NETWORK:
*
FALLBACK:
test.html
test.html runs fine in online mode in localhost:8080/myapp/test.html
But when I stop the TOMCAT and try to run it
this is what I get -
Why is my HTML page test.html not getting served from cache when I stop TOMCAT server!
Thanks
Try changing the doctype of your HTML doc to
<DOCTYPE html>
the manifest attribute is HTML5.
https://developer.mozilla.org/en-US/docs/Web/HTML/Using_the_application_cache

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 :))

Redirecting users in JSP from within a includes - java syntax error

So my setup for my web application is that I have a general header and footer and then I just include them in all my other pages so that all the common elements for all the pages are in a single page. The only problem I'm running into is when I want to redirect the user back to a login page if the "username" session has not already been created.
The problem that I"m running into is that I have an if statement at the top of my header.jsp and then I have the else in the footer.jsp and it is giving me a java syntax error. Any ideas? Here is the code I'm referring to...
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%
if(session.getAttribute("username") != null)
{
%>
<%# 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">
<!-- CSS files -->
<link rel="stylesheet" href="../CSS/headerStyle.css" type="text/css" media="screen" />
<title>Insert title here</title>
</head>
<body>
<div id="container">
<div id="header">
<div id="headerTitle">Title</div>
</div>
</div>
<%} %>
And then here is the footer
<!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=UTF-8">
<link rel="stylesheet" href="../CSS/headerStyle.css" type="text/css" media="screen" />
</head>
<body>
<div id="footer"></div>
</body>
</html>
<%
else
{
response.sendRedirect("../wa_login/login.jsp");
}
%>
However it is giving me an error on the else statement because the else doesn't have an if statement because it's in the header file.
Each .jsp has to compile as an independent unit. Hence the error.
Why not just perform the check in the header and redirect from there ?
<%
if(session.getAttribute("username") == null)
{
response.sendRedirect("../wa_login/login.jsp");
}
%>

Categories