jstl - unable to load class for jsp - java

When I try to add jstl tags into my jsp I get this:
HTTP Status 500 - org.apache.jasper.JasperException: Unable to load class for JSP
JSP may look like this:
<%# taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<html>
<body>
<c:forEach items="${list}" var="post" >
<tr>
<td>${post.author}</td>
</tr>
</c:forEach>
</body>
</html>
I also tried to write
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
the result is the same.
Why does it happen?

Related

Href isn't redirecting

I have this code in JSP:
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <%# taglib prefix="security" uri="http://www.springframework.org/security/tags" %> <%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%-- Created by IntelliJ IDEA. User: PC Date: 02.05.2022 Time: 15:20 To change this template use File | Settings | File Templates.
--%> <%# page contentType="text/html;charset=UTF-8" language="java" %>
<html> <head>
<title>Title</title> </head> <body> <h1>Dashboard</h1> <br>
<table>
<tr>
<th>Banners</th>
<th>Localization</th>
</tr>
<%--#elvariable id="banners" type="java.util.List<pl.coderslab.entity.Banners>"--%>
<c:forEach var="banner" items="${banners}">
<tr>
<td>Banner</td>
<td>${banner.street}</td>
<td> <a href="localhost:8080/dashboard/info/${banner.id}" >Wiecej informacji </a></td>
<td> <a href="localhost:8080/dashboard/edit/${banner.id}" >Edytuj </a></td>
<td> <a href="localhost:8080/dashboard/delete/${banner.id}" >Usun </a></td>
</tr>
</c:forEach>
</table>
</body> </html>
and also have controller:
#RequestMapping(value = "/dashboard/info/{id}", method = RequestMethod.GET)
public String showInfo(Model model, #PathVariable("id") int id){
List<Banners> banners = bannerDao.getBannerById(id);
model.addAttribute("banner", banners);
return "showInfo";
}
#RequestMapping(value = "/dashboard/info/{id}", method = RequestMethod.POST)
public String info(){
return "showInfo";
}
The problem is that these href's aren't redirecting. When i click on them nothing happens, as if they were simple buttons. I don't have an idea, what to do here?
1st edit:
Okay so answer from Halil Ibrahim Binol worked but now it shows me 404 error, even if I have #RequestMapping to this address
Did you try adding http prefix?
<a href="http://localhost:8080/dashboard/info/${banner.id}" >Wiecej informacji</a>
Or you can use;
Wiecej informacji
This will be use current page protocol. When you are in https page it will convert to https://localhost:8080/...
Edit:
Alternatively, when your code is running in same server. You can use;
Wiecej informacji

It is possible to pass jsp code as a parameter?

suppose I have a header (which is common for all pages regarding one type of object).
<%# page session="false" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%# taglib prefix="header" uri="headerDir" %>
<%# taglib prefix="tabs" uri="tabDir" %>
<div id="content" class="inside>
<header:myHeader headerData="${myModel}">
<tabs:myTabs argument="${someArg}"
....
so In views that are shared for different objects now I am doing
<c:choose>
<c:when test="${myModel.type ==FIRST_TYPE}>
<header:myHeader headerData="${myModel}">
</c:when>
<c:otherwise>
<header:secondHeader headerData="${myModel}">
</c:otherwise>
<c:choose>
but I would like to avoid this choose, I am able to send this
as a parameter as I am passing arguments? so can I do something like the following
<%# page session="false" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%# taglib prefix="header" uri="headerDir" %>
<%# taglib prefix="tabs" uri="tabDir" %>
<div id="content" class="inside>
<header:myHeader headerData="${myModel}">
<tabs:myTabs argument="${someArg}" headerToUse="${myHeader}" //in some way pass the header?
....

Issue when deploying Struts app that runs on weblogic 8.1 to weblogic 11g

If I deploy an ear file on my local weblogic 8.1 server, it is working perfectly fine. But when I deploy it on Weblogic 11g, it gives an error.
Here is the scenario –
The first page of the application asks you to select the user. On user selection it will execute the RolesAction and take you to the roles page wherein the roles that are assiociated with the user will come as a drop down.
Once I deploy Argus application and select user on test login page, entire RolesAction class is getting executed but instead of getting page with roles associated to that user in the dropdown, I am getting “Error 404—Not Found” error page and in log file getting below mentioned error.
<Mar 20, 2011 8:20:42 PM GMT> <Error> <HTTP> <BEA-101017> <[ServletContext#406125315[app:ArgusDEV module:ArgusWeb path:/ArgusWeb spec-version:null]] Root cause of ServletException.
java.lang.NoSuchMethodError: org/apache/struts/config/ForwardConfig.getContextRelative()Z
at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:298)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:232)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
Any inputs??
My Roles.jsp has the tld declaration as below:
<%# taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%# taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%# taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
Do you see any issue wrt the tld declaration?
Thoughts?
Thanks!
EDIT:
The first page that comes up in the application wherein you select the user is the Login.jsp. In this jsp, the tlds are declared as below:
This page is displyed. However, the roles.jsp page is the one that gives the error.
Login.jsp tld declaration:
<%# taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%# taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%# taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
Both the jsp's have the same tld declaration, and 1 gets displayed whereas the other one gives an error.
Ideas?
EDIT:
Roles.jsp
<%# taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%# taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%# taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link rel="stylesheet" type="text/css" href="css/arg.css" />
</head>
<form name="rolesForm" method="post">
<logic:present name="VIEW_BEAN" scope="request">
<logic:notEmpty name="VIEW_BEAN" property="userId" scope="request">
<input type="hidden" name="Id" value="<bean:write name="VIEW_BEAN" property="userId"/>">
</logic:notEmpty>
</logic:present>
<table border="0" cellpadding="1" cellspacing="0" width="95%" bgcolor="#FFFFFF">
<tr>
<td height="19"> </td>
</tr>
<tr>
<td width="100%" align="center" class="epi-dataTableLiteNew">
<font size="2"><b>Select a Role:</b> </font>
<select size="1" name="roleType" class="textbox" ">
<option value="">Select ---</option>
<logic:notEmpty name="VIEW_BEAN" property="roleList" scope="request">
<logic:iterate id="record" name="VIEW_BEAN" property="roleList" scope="request">
<option value="<bean:write name="record" property="roleID"/>"><bean:write name="record" property="roleName"/></b></option>
</logic:iterate>
</logic:notEmpty>
</select>
<input type="submit" value="Submit" onClick="return selectRole()" style="border:1px ridge #000000; height:22px; font-weight:bold cellpadding="0" cellspacing="0" 100%>
<p> </p>
<p> </p>
<p> </p>
</td>
</tr>
</table>
</form>
</body>
</html>
Login.jsp
<%# taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%# taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%# taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html>
<head>
</head>
<%# page
language="java"
%>
<meta http-equiv="Content-Type" content="text/html" />
<link rel="stylesheet" type="text/css" href="css/arg.css" />
<title>Home</title>
<%
String userid=request.getHeader("user");
String isLoginPage=request.getParameter("isUser");
%>
<!-- Please select the user from the list and press continue: -->
<form name="homePageForm" action="RolesAction.do" method="post">
</form>
</body>
</html>
EDIT:
struts-config.xml
<action
path="/roles"
name="HomePageForm"
type="org.springframework.web.struts.DelegatingActionProxy"
scope="request">
<forward name="success" path=".rolespage"/>
</action>
The action to be called for the url pattern is in the spring.xml file.
Checked the application lib folder to find struts-core-1.3.8.jar as well as struts.jar. It is because of this that the exception was thrown.
struts.jar has the forwardConfig class and getContextRelative() method.
struts-core-1.3.8.jar has the forwardConfig class , but not the getContextRelative() method.
This was causing the issue.
Therefore remove struts.jar so that 1.3.8 version is used.
-- Additionally add struts-extras-1.3.8.jar to the application lib
-- In the jsp, correct the tag lib uri to:
<%# taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%# taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
This solves the problem
Struts 1.1 <%# taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
Struts 1.2.x <%# taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
Please use above tag lib uri . Hope will solve your issue.

JSF RuntimeException: Cannot find FacesContext

When I write <h:outputText value="Login Name"/> tag in my JSP, I get the following exception message:
Cannot find FacesContext
Without that my JSP works fine. Here is my JSP:
<%# page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<%# taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%# taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<body>
Login Name <input type="text" value=""/><br>
<h:outputText value="Login Name"/>
Password<input type="password" value=""/><br>
<input type="submit" value="Login">
</body>
</html>
There are two flaws in your code:
The root cause of this exception is that you forgot to pass the request through the url-pattern of the FacesServlet as definied in web.xml. If the JSP page is for example named page.jsp and the url-pattern of the FacesServlet is for example *.jsf, then you need to invoke it by http://example.com/context/page.jsf instead of .jsp. This way the FacesServlet will be invoked and create the FacesContext. Otherwise the JSF components in the page will complain that the FacesContext cannot be found and you will face this particular exception.
The <f:view> is missing in the page. Wrap the entire <html> in it. E.g.
<%# page pageEncoding="UTF-8" %>
<%# taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%# taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<!doctype ... >
<f:view>
<html>
...
</html>
</f:view>
By the way, that import attribute in the <%#page> is completely superfluous. Get rid of it.

Please help with my JSP Internationalization problem

I have problem with I18N in JSP, specifically, with forms.
When I enter some Czech characters (e.g., "ěščřžýá...") into my page one form, into the field "fieldOne", and then show text from that field on page two, instead of Czech characters I see this as "ÄÄ". (Note, the second page gets the Czech characters with "request.getProperty("fieldOne")")
Here is the source code:
Page one:
<%#page contentType="text/html"%>
<%#page pageEncoding="UTF-8"%>
<%# taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%# taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%# taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<html>
<head></head>
<body>
<form action="druha.jsp" method="post">
<input type="textarea" name="fieldOne">
<input type="submit">
</form>
</body>
</html>
Page two:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%# taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%# taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%# taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<html>
<head></head>
<body>
<h1>The text: </h1> <%=request.getProperty("fieldOne")%>
</body>
</html>
Thanks for help...
Which container are you using? This information is important for this kind of problems.
Anyway, try calling
request.setCharacterEncoding("UTF-8");
before reading the parameter. Sometimes setting the page encoding in the header directive isn't enough. You definitely need to do this in Tomcat and servlets, I assume that this could be also the case for JSPs.

Categories