JSP doesn't see JavaBeans - eclipse

everybody!
Can't solve this problem:
org.apache.jasper.JasperException: JBWEB004062: Unable to compile class for JSP:
JBWEB004060: An error occurred at line: 14 in the jsp file: /indexJB.jsp
packt.book.jee_eclipse.ch2.bean.LoginBean
cannot be resolved to a type
11: <%if ("POST".equalsIgnoreCase(request.getMethod())&&
12:
request.getParameter("submit")!=null)
13: { %>
14: <jsp:useBean id="loginBean"
15:
class="packt.book.jee_eclipse.ch2.bean.LoginBean">
16:
<jsp:setProperty name="loginBean" property="*"/>
17: </jsp:useBean>
I use:
WildFly 23
Eclipse Version: 2021-09 (4.21.0)
What I found in Internet:
Note
See the detailed error message under More Information.
​This issue occurs because JBoss EAP 6.2 server runtime is using unsupported JDK. Verify the following log statements for reference:
java.library.path = C:\Program Files\Java\jdk1.8.0_20\bin
java.runtime.name = Java(TM) SE Runtime Environment
java.runtime.version = 1.8.0_20-b26
Solution
​To resolve this issue, do as follows:
Point your JBoss EAP 6.2 server to a supported JDK that is JDK 1.7.x
(best is 1.7.0_25).
Restart the application server.
But how to point???
Thanks in ADVANCE!
The whole code is here:
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W#C//DTD HTML 4.01 Transitional//EN"
"http://www.w3org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login</title>
</head>
<% String errMsg = null; %>
<%if ("POST".equalsIgnoreCase(request.getMethod())&&
request.getParameter("submit")!=null)
{ %>
<jsp:useBean id="loginBean"
class="packt.book.jee_eclipse.ch2.bean.LoginBean">
<jsp:setProperty name="loginBean" property="*"/>
</jsp:useBean>
<%
if (loginBean.isValidUser())
{ out.println("<h2>WElcome, Admin!</h2>");
out.println("You are logged in");
}
else
errMsg = "Invalid user ID or password!";
}
%>
<body>
<h2>Login:</h2>
<%if (errMsg!=null ) {%>
<span style="color: red;"><%out.print(errMsg); %> </span>
<%} %>
<form method="POST">
User Name: <input type="text" name="userName" style="color: Green; background-color: Yellow"><br>
Password: <input type="password" name="password" style="color: Yellow; background-color: Silver"><br>
<button type="submit" name="submit">SUBMIT</button>
<button type="reset">Reset</button>
</form>
</body>
</html>

The problem was solved:
Right click on project-> choose properties -> Java Build Path -> choose third marker Libraries -> put cursor on Classpath -> on right menu choose Add Class Folder -> choose folder for classes -> Apply and Close.
I also restarted Eclipse just in case.
And my JSP finally sees Java Beans!
Hope that will help=)

Related

HTTP Status 404 – Not Found Tomcat

This is my code. I'm trying to add values to my table using JSP and MYSQL. Name of the table and database is correct.
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# page import ="java.sql.*" %>
<%# page import ="javax.sql.*" %>
<!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>Inserting Data from form</title>
</head>
<body>
<h1> Insert a Record</h1>
<form method="post" action="insertrecord.jsp">
<table>
<tr>
<td>
<input type="text" name="uname">
</td>
<td>
<input type="password" name="upass">
</td>
<tr>
<tr>
<td><input type="submit" name="submit" value ="submit"></td>
</tr>
</table>
</form>
<%
String sub = request.getParameter("submit");
if(sub!=null)
{
String uname=request.getParameter("uname");
String password = request.getParameter("upass");
if(uname!=null && password!=null)
{
try
{
Connection con;
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/demo","root","");
Statement stmt = con.createStatement();
int i = stmt.executeUpdate("insert into user values ('"+uname+"','"+password+"')");
out.println("Record Inserted Successfully");
stmt.close();
con.close();
}
catch(SQLException e)
{
out.println(e.getMessage());
}
}
}
%>
</body>
</html>
When I click on submit. I'm getting this error:
HTTP Status 404 – Not Found
Type Status Report
Message /something/insertrecord.jsp
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/9.0.5

Eclipse: jsp, Syntax error on token , delete this token

Hi I have a Maven project. I am working with Eclipse STS. I am getting an error on a jsp file.
Syntax error on token "<", delete this token (line 22)
Multiple annotations found at this line: (line 27)
- Syntax error, insert ")" to complete Arguments
- Syntax error, insert ") BlockStatement" to complete
IfStatement
- Syntax error, insert "}" to complete Block
Below is my code for jsp file:
<%# page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%# taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%# taglib prefix="json" uri="http://www.atg.com/taglibs/json" %>
<%# taglib uri="http://www.springframework.org/security/tags"
prefix="security"%>
<security:authentication var="principal" property="principal" />
<script type="text/javascript">
var chooseSuperSellerPlaceholder = '<fmt:message
key="global.chooseSuperSeller" />';
var chooseSellerPlaceholder = '<fmt:message key="global.chooseSeller" />';
var chooseCustomerPlaceholder = '<fmt:message key="global.chooseCustomer"
/>';
var thisNotify;
$(function(){
initDate();
loadNotifications();
initDigitalClock();
<security:authorize access="hasAuthority('ROLE_SUPER_ADMIN')">
initCombobox('#h-s-seller', 'SUPER_SELLER');
initCombobox('#h-seller', 'SELLER');
initCombobox('#h-customer', 'END_CUSTOMER');
loadChildren('#h-s-seller', 'SUPER_SELLER', -1);
<c:if test="${sessionScope.SELECTED_CUSTOMER != null}">
loadChildren('#h-s-seller', 'SUPER_SELLER', ${sessionScope.SELECTED_CUSTOMER.parent.parent.parent.id});
loadChildren('#h-seller', 'SELLER', ${sessionScope.SELECTED_CUSTOMER.parent.parent.id});
loadChildren('#h-customer', 'END_CUSTOMER', ${sessionScope.SELECTED_CUSTOMER.parent.id});
</c:if>
</security:authorize>
<security:authorize access="hasAuthority('ROLE_SUPER_SELLER')">
initCombobox('#h-seller', 'SELLER');
initCombobox('#h-customer', 'END_CUSTOMER');
loadChildren('#h-seller', 'SELLER', ${principal.user.customer.id});
<c:if test="${sessionScope.SELECTED_CUSTOMER != null}">
loadChildren('#h-seller', 'SELLER', ${sessionScope.SELECTED_CUSTOMER.parent.parent.id});
loadChildren('#h-customer', 'END_CUSTOMER', ${sessionScope.SELECTED_CUSTOMER.parent.id});
</c:if>
</security:authorize>
<security:authorize access="hasAuthority('ROLE_SELLER')">
initCombobox('#h-customer', 'END_CUSTOMER');
loadChildren('#h-customer', 'END_CUSTOMER', ${principal.user.customer.id});
<c:if test="${sessionScope.SELECTED_CUSTOMER != null}">
loadChildren('#h-customer', 'END_CUSTOMER', ${sessionScope.SELECTED_CUSTOMER.parent.id});
</c:if>
</security:authorize>
});
Any ideas what I'm doing wrong?
Thanks.

How to call Java Class from JSP page? Cloud9 & OpenShift JBoss

I am new to c9. I created a Openshift JBoss application server & imported into C9 via GitHub.
I have a simple Java class in Main\Java\initial.class.
public class initial {
public static void main(String[] args) {
String prn = disp();
System.out.println(prn);
}
public static String disp()
{
String str=" JAVARANCH ";
return str;
}
}
I have a jsp page called from index.html, I am just trying to display the variable 'prn' in the jsp page.
<HEAD>
<TITLE>JBossAS7 JSP snoop page</TITLE>
<%# page import="javax.servlet.http.HttpUtils,java.util.Enumeration" %>
<%# page import="java.lang.management.*" %>
<%# page import="java.util.*" %>
<%# page import="initial" %>
</HEAD>
<BODY>
<H1>WebApp JSP Snoop page</H1>
<img src="images/jbosscorp_logo.png">
<h2>JVM Memory Monitor</h2>
<input type="text" name="text1" size="100" value="<%=prn%>">
But, I am getting below error at the JSP page:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 10 in the generated java file
The import initial cannot be resolved
An error occurred at line: 15 in the jsp file: /snoop.jsp
prn cannot be resolved to a variable
12: <img src="images/jbosscorp_logo.png">
13:
14: <h2>JVM Memory Monitor</h2>
15: <input type="text" name="text1" size="100" value="<%=prn%>">
16:
17: <table border="0" width="100%">
18:
How do I interact with a Java class from my JSP?
thanks.
EDIT due to two answers:
I think the main issue is: the class 'initial' is not being imported successfully. My call to Prn was wrong, I understand that now, but the Import itself is not working.
some suggested having the class inside a package. But Cloud9 IDE does not have an option to create a package.
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 10 in the generated java file
The import initial cannot be resolved
If you try this :
Java class:
public class Initial {
public static String getDisp() {
return "JAVARANCH";
}
}
JSP file :
<HEAD>
<TITLE>JBossAS7 JSP snoop page</TITLE>
<%# page import="javax.servlet.http.HttpUtils,java.util.Enumeration" %>
<%# page import="java.lang.management.*" %>
<%# page import="java.util.*" %>
<%# page import="Initial" %>
</HEAD>
<BODY>
<H1>WebApp JSP Snoop page</H1>
<img src="images/jbosscorp_logo.png">
<h2>JVM Memory Monitor</h2>
<input type="text" name="text1" size="100" value="<%=Initial.getDisp()%>">
</BODY>
You can access your class from your jsp by adding the following.
<input type="text" name="text1" size="100" value="<%= initial.disp() %>">
or by adding a jsp scriptlet prior to your input
<%
String prn = initial.disp();
%>
<input type="text" name="text1" size="100" value="<%= prn %>">
Notice I am using your method disp() not main(). Main is static void with no return.

ClassNotFound Exception: org.postgresql.Driver from [Module "deployment.ValidateUser.war:main" from Service Module Loader]

I am trying to connect with postgre databse with jsp program using Eclipse IDE,
I am getting this error:
"java.lang.ClassNotFoundException: org.postgresql.Driver from [Module
"deployment.ValidateUser.war:main" from Service Module Loader]".
I had put the jar files required for my project even though i am getting classnotfound exception error.
<%#page import="com.uservalidation.FarwordNames"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
<%-- Imports --%>
<%# page import="java.sql.*"%>
<%# page import="java.util.*"%>
<%# page import="javax.servlet.*" %>
<%# page import="javax.servlet.http.*" %>
<%-- HTTP header --%>
<%response.addHeader("Cache-Control","no-cache");
response.addHeader("Pragma","no-cache");
response.addHeader("Expires","0");
%>
<%-- Variables that will be written --%>
<%
String fname = request.getParameter("fname");
String mname = request.getParameter("mname");
String lname = request.getParameter("lname");
String dob = request.getParameter("dob");
String addr = request.getParameter("addr");
%>
<%-- Creating new staff account - writing --%>
<%
try{
Class.forName("org.postgresql.Driver");
String conURL= "jdbc:postgresql://192.168.1.157:5432/MIPSUITE_DEV";
Connection con = DriverManager.getConnection(conURL,"mipsuitedev01","mipsuitedev01");
Statement st = con.createStatement();
//int status = st.executeUpdate("insert into users(fname,mname,lname,dob,address) values('"+fname+"',"+mname+"','"+lname+"','"+dob+"','"+addr+"')");
/* if(status>0){
out.println("Update sucessful");
}
else{
out.println("Update unsuccessful");
} */
st.close();
con.close();
}
catch(Exception e){
out.println(e);
}
%>
</body>
</html>
It seems to be fixed the problem by removing all resteasy/jaxrs/jboss libraries from the WAR file's WEB-INF/lib/.
Put postgresql driver
jar files into WEB-INF/lib folder.
I think it's should be work for you.

Value is not posting in a .jsp page

This is the code that I have for the page that I'm testing out:
Don't worry the startpage and endpage code works.
<% startpage(out); %>
<%
String newusers = request.getParameter("users");
int i = 0;
if (newusers != null){
while(i<10)
{
out.println("<h2>newusers</h2>");
i++;
}
}
%>
<form action="guestAdder.jsp" method=post>
<textarea name=users rows=20 cols=100>
</textarea>
<p>
<input type=submit name=doadd value="Add Users">
</form>
<% endpage(out); %>
it is a HTTP Status 500 - java.lang.NoClassDefFoundError: org/apache/jsp/guestAdder_jsp (wrong name: org/apache/jsp/guestadder_jsp)
I'm guessing you've renamed your jsp file from guestadder.jsp to guestAdder.jsp. Are you on Windows (which isn't case sensitive for filenames)? Looks like the servlet class generated from the JSP page is overwriting the old lowercase-named file but the file isn't being renamed, i.e it is keeping its old name of guestadder_jsp.class
Clear the directory used to cache the servlet classes generated from JSPs - in Tomcat this is tomcat/work