Tomcat 6.0.37 not processing jstl tag statements - jstl

I have a simple test page with the following statement but it appears that the ${} tags are not being processed by Tomcat and i get no errors in the log.
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>JSTL Test Example</title>
<body>
Setting value using c:out <c:set var="name" scope="request" value="Testing" /><br>
Value is: <b><c:out value="${name}"/></b><br>
</body>
</html>
Browser Output:
Setting value using c:out
Value is: ${name}
Using the information from https://stackoverflow.com/tags/jstl/info
I verified
1) Tomcat lib has jstl.2 jar , there are no duplicate jars - if i remove this jar i get a big exception complaining about missing tag classes.
2) My webapp does not have jstl jar in the classpath.
3) Tomcat web.xml has the correct servlet specification
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
Any help would be greatly appreciated.
Thanks

their may be conflict of jsp-api jar
remove jstl.version.jar from tomcat lib
and add directly dependency in your project
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
and try !

Related

SpringMVC w/ Maven - not able to get Servlet to find second page

I am trying to build a demonstrator example for a Spring MVC project that uses DispatcherServlet, following a precedent: https://www.youtube.com/watch?v=g2b-NbR48Jo&t=551s
It has been straightforward, up until I tried to add a second JSP file to the project and the program is not able to access it after initiating the main page successfully. Briefly, this project takes two numbers in the "index.jsp" file and then returns a plain text message in the "display.jsp" file, in advance of building an addition ability into the Controller...
I am also using Apache 10.0.2 for this and Spring Tools Suite 4.10.0.RELEASE with Eclipse.
This is the code for making the above image in the index.jsp file:
<html>
<body>
<form action="add">
<input type="text" name="t1"><br>
<input type="text" name="t2"><br>
<input type="submit">
</form>
</body>
</html>
The display.jsp file simply is this, generated by Eclipse, and this is the file my program can't seem to find:
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3c//DD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html14/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
I'm here
</body>
</html>
The web.xml file that initiates the DispatcherServlet and sets the URL pattern is also standard issue:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>telusko</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>telusko</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
The telusko-servlet.xml file has the expected content to facilitate annotation use in the controller:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:ctx="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd ">
<ctx:annotation-config></ctx:annotation-config>
<ctx:component-scan base-package="com.telusko"></ctx:component-scan>
</beans>
The AddController.java file:
package com.telusko;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
//will be responsible for adding two numbers
#Controller
public class AddController {
#RequestMapping("/add")
public String add()
{
return "display.jsp";
}
}
POM file dependencies, but i don't think these connect to the issue:
Last thing, project structure:
The error I get after clicking the "Submit" button on the first page is this:
It is generally clear that Apache cannot find the page, but I cannot understand fully why. I've tried a number of resolutions to resolve the problem:
Eclipse is using the Tomcat installation in the server settings
The location is also set to Servers/Tomcat v10.0 at localhost.server
Tried changing the URL pattern to "/", "/Dispatcher/", to no avail, and left it back with just the forward slash
Deleted the "target" folder in the Maven file and let it recreate
Corrected header references in the XML file (i.e. adding a missed "/schema/")
Updated/cleaned Maven project and server, separately. It leads to a separate error :
And this error is solved with adding <load-on-startup>1</load-on-startup> under the set of tags, at which point it reverts to the original 404 error.
I am using later version of JAR files, but I'm not sure if it might be a compatibility issue with STS4 and the version in the project.
Running the "display.jsp" file on its own does make it show with the "I'm here" message.
Targeted Runtimes for the project is set to Apache Tomcat v10.0.
I am exploring other possible angles on this problem, but it has proven to be persistent. Thank you in advance for your insight!

the message is not printed correctly on the view page in spring mvc [duplicate]

This question already has answers here:
EL expressions not evaluated in JSP
(5 answers)
Closed 7 years ago.
JSTL variable values are not shown in EL. For example this code:
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%# taglib prefix="s" uri="http://www.springframework.org/tags" %>
<html>
<body>
<c:forEach var="i" begin="1" end="5" >
<c:out value="${i}" />
</c:forEach>
</body>
</html>
browser renders like: ${i} ${i} ${i} ${i} ${i}
Or this one:
<c:set var="someVar" value="Hello"/>
<c:out value="${someVar}"/>
browser displays: ${someVar}
I'm using Spring-MVC 3 and Maven to build the sample project, deploying it to Tomcat 7.
In Spring's context I have view resolver configurated as follows:
<bean class=
"org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="
org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/WEB-INF/"></property>
<property name="suffix" value=".jsp" />
</bean>
Model variables passed form Spring's controller not shown as well.
Mavens pom.xml has following jstl related dependencies:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
So, any suggestions how to resolve this?
So, the EL (those ${} things) doesn't get executed? That can happen when your servletcontainer runs at Servlet 2.3 / JSP 1.2 modus or lower, while you're using JSTL 1.1 or newer. During the change from JSTL 1.0 to 1.1, EL was moved from JSTL into JSP. That was JSP 2.0, which is part of Servlet 2.4. JSP 1.2 and older doesn't have EL bundled. JSTL 1.1 and newer doesn't have EL bundled.
You need to make sure that your web.xml root declaration conforms at least Servlet 2.4. As you're using JSP 2.1, which is part of Servlet 2.5, you're apparently targeting a Servlet 2.5 compatible container. So, make sure that your web.xml root declaration conforms Servlet 2.5:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"
version="2.5">
<!-- Config here. -->
</web-app>
Tomcat 7 is however a Servlet 3.0 compatible container. I'd consider changing maven pom to declare Servlet 3.0 / JSP 2.2 so that you can benefit all the new Servlet 3.0 features.
See also:
Our JSTL wiki page
History of EL

JSTL tag is not showing its value on View page [duplicate]

There's a small problem with my servlets/jsp web application. I'm trying to use jstl in jsp page. When I use any tag for example:
<c:out value="${command}"/>
it shows me
${command}
in my browser instead of parameter 'command' value. I'm using maven (and I guess the problem is here). Here is pom xml dependencies:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
my web.xml declaration tag:
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
and jsp part:
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>Parsing results</title>
<link type="text/css" rel="stylesheet" href="css/page.css"/>
<link type="text/css" rel="stylesheet" href="css/table.css"/>
</head>
<body>
<h2 align="center">Results of
parsing. Parsing method = <c:out value="${command}"/></h2>.......
EDIT:
Code, which sets command value, is simple:
request.setAttribute("command", parser.getName());
then goes
request.getRequestDispatcher(redir).forward(request, response);
Tell me please, what I'm doing wrong!
Thx!
Yes, i have doctype in web.xml <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "java.sun.com/dtd/web-app_2_3.dtd"; >
Remove that <!DOCTYPE> from web.xml and make sure that the <web-app> is declared conform Servlet 2.4 or newer and all should be well.
A valid Servlet 3.0 (Tomcat 7, JBoss AS 6-7, GlassFish 3, etc) compatible web.xml look like below in its entirety, without any <!DOCTYPE>:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<!-- Config here. -->
</web-app>
For Servlet 3.1 (Tomcat 8, WildFly 8-11, GlassFish/Payara 4, etc) it look like below:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<!-- Config here. -->
</web-app>
For Servlet 4.0 (Tomcat 9, WildFly 12-21, GlassFish/Payara 5, etc) it look like below:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<!-- Config here. -->
</web-app>
For Servlet 5.0 (Tomcat 10, WildFly 22-26, GlassFish/Payara 6, etc) it look like below:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
version="5.0">
<!-- Config here. -->
</web-app>
When using JSTL 1.1 or newer, you need to assure that your web.xml is declared in such way that the webapp runs in at least Servlet 2.4 modus, otherwise EL expressions won't work in the webapp.
When still having a Servlet 2.3 or older <!DOCTYPE> or <web-app> in web.xml, even though you already have a Servlet 2.4 or newer XSD, then it would still be forced to run in Servlet 2.3 or older modus, causing the EL expressions to fail.
The technical reason is, EL was originally part of JSTL 1.0 and not available in Servlet 2.3 / JSP 1.2 and older. In JSTL 1.1, EL was removed from JSTL and integrated in JSP 2.0, which goes along with Servlet 2.4. So, if your web.xml is declared to run the webapp in Servlet 2.3 or older modus, then JSP would expect to find EL in JSTL library, but this would in turn fail if it's a newer JSTL version, lacking EL.
See also:
Difference between JSP EL, JSF EL and Unified EL - for a history of EL
Our JSTL wiki page
In my case for web.xml file (version="3.0") I had to run the application on Tomcat server v.8 instead of v.7, otherwise I had the same issue as you. Hope this helps someone...
<?xml version="1.0" encoding="ISO-8859-1" ?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
Setting <%# page isELIgnored="false" %> at the top of the page helped to me. Don't know why it was the root of the problem in my case. Not clear why yet.
Try placing the jdbc driver class in the WEB-INF -> lib folder and verfiy the versions of servlet and jar file used. In my case, I used mssql-jdbc-8.2.2.jar and update the same in pom.xml
My JSP page also couldn't recognize the <c:choose></:choose>. Always executed the false condition i.e <c:otherwise>. This is what was happening.
This was an inner JSP page i.e
<jsp:include page="your-inner-page.jsp"/>
The inner JSP was loading first and did not have the below tag libraries. They were placed on the outer JSP. Adding them to the inner worked for me.
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form" %>

ATG<dsp:setvalue> Trouble with setting values using JSTL

Got some trouble with using jstl in atg jsp page. Added
<%# taglib uri="http://java.sun.com/jstl/core" prefix="c" %> and some library at /WEB-INF/lib (standard.jar, jstl.jar).
My web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
So <dsp:getvalueof param="id" var="prodId"/>
<c:set var="link" value="genericproduct.jsp?id=${prodId}"/> works fine and shows for example "genericproduct.jsp?id=prod180007",but ${prodId} shows nothing,at the moment <c:out value="${prodId}"/> works. And <dsp:setvalue bean="CustomFormHandler.errorURL" value="genericproduct.jsp?id=${prodId}"/> doesn't works - "genericproduct.jsp?id=${prodId}". Version of JSTL 1.0, application runs on jboss 4.0.5GA.I look forward to your reply.Thanks!
<%# page isELIgnored="false" %>
<%#taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>

JspException and PageContext cannot be resolved

This is a follow up to a question on accessing resources in jsp page of spring mvc app
Thanks to #kmb385 I was able to resolve that problem but now I get the following eclipse errors in my JSP file
javax.servlet.jsp.JspException cannot be resolved to a type
and
javax.servlet.jsp.PageContext cannot be resolved to a type
as suggest by kmb385, here is my controller:
#Controller
public class AdminController {
#RequestMapping("/")
protected ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {
ModelAndView model = new ModelAndView("index");
model.addObject("msg", "hello world");
return model;
}
}
and here is my index.jsp page just in case:
<%# 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">
<!-- <link type="text/css" rel="stylesheet" href="css/style.css"/> -->
<style type="text/css">
<%#include file="css/style.css" %>
</style>
<title>My Project - MainPage</title>
</head>
<body>
<h2 class="main_heading2">My Project - MainPage</h2>
<div style="float: right; width: 30%; text-align: center">
<p style="float:left;">an image should be here</p>
<img src="images/logo.jpg" alt="Logo"/>
<img src="${pageContext.servletContext.contextPath}/resources/images/logo.jpg" />
</div>
</body>
I have come across "solutions" to this by disabling it in the JSP validator but Please do not suggest this unless you can give a legitimate reason. I would rather correct this issue properly
Any Help appreciated
UPDATE:
Build path screen grab as requested by #kmb385
Try setting the servlet-api dependency in your pom.xml to provided. This jar maybe conflicting with the tomcat provided servlet-api.jar.
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
Also be sure to include the jsp-api dependency, once again set as provided:
<!-- Servlet -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
Make sure all of your maven dependencies are being used to build the project by right clicking your project > Properties. On the deployment assembly tab click the add button, then Java Build Path Entries, then Maven Dependencies and finally Finish.
You may also need to add your maven dependencies to the build path. Right click your project > Maven > Update Project Configuration.
If you have downloaded all the dependencies in maven and the error is still not getting away, follow the steps below:
Right click on project and go to properties
Click over target run time
Check the box in front of the server you are using.
This should work.
Try import the class.
Modify your jsp's first line to look like this;
<%# page language="java" import="javax.servlet.jsp.PageContext" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>
Add to the pom.xml dependencies:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
JSP:
Make sure to add on jsp, before tag:
<%# taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
Get the context on JSP:
<c:set var="contextPath" value="${pageContext.request.contextPath}"/>
Import style css:
<link type="text/css" rel="stylesheet" href="${contextPath}/css/yourCssFile.css"/>
Dispatcher-servlet:
On your "spring-dispatcher-servlet.xml" add the following lines:
<beans xmlns="... xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="...
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<mvc:resources mapping="/resources/**" location="/resources/css/" />
Maybe, you need to add this adapters:
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/> [Optional]
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="order" value="0"/>
</bean>
explained here: how to include js and css in jsp with spring MVC
How to solve javax.servlet.jsp.PageContext cannot be resolved to a type
1:- Select your project and Right click
2:- Go to Properties
3:- Click Targated Runtimes
4:- Check mark "Apache Tomcat v8.0"
I am using Apache v8.0 in my case
This will solve the problem
<!-- Need this to compile JSP -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
This alternative worked for me <%=request.getContextPath()%> which gets the Application context.

Resources