Here's my current situation:
I've created a Maven project from my shell, using this command:
mvn archetype:generate -DgroupId=it.my.current.package.example -DartifactId=Example -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
mvn package
Then I opened Eclipse, imported the project as a Maven one. I added those dependencies to my
pom.xml
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
Then I created a JSP and a Servlet.
My servlet just sets some variables and my JSP use them with some JSTL.
I've added on my JSP this tag:
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
and the code on my JSP is really simple:
<c:forEach items="${requestScope.empList}" var="emp">
<tr>
<td><c:out value="${emp.id}"></c:out></td>
<td><c:out value="${emp.name}"></c:out></td>
<td><c:out value="${emp.role}"></c:out></td>
</tr>
</c:forEach>
My Servlet it's doing this:
List<Employee> empList = new ArrayList<Employee>();
Employee emp1 = new Employee();
emp1.setId(1); emp1.setName("Sam");emp1.setRole("Developer");
Employee emp2 = new Employee();
emp2.setId(2); emp2.setName("John");emp2.setRole("Manager");
empList.add(emp1);empList.add(emp2);
request.setAttribute("empList", empList);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/home.jsp");
rd.forward(request, response);
Employee is a simple Bean.
When I try to run this application, from my Servlet, it actually shows me this, on my JSP:
${emp.id} ${emp.name} ${emp.role}
And it's not showing the value that I set on my Servlet.
I'm totally new to JSTL, so I googled first for my issue. I tried adding jstl-1.2.jar on my $TOMCAT_HOME/lib directory, but it didn't work.
What's the problem then?
EDIT: what are the configuration I need to do on my container and project to run JSTL? Isn't enough what I've made?
I think that it is not a problem with JSTL. This notation: ${emp.role} is EL (Expression Language) and it is not working.
Don't you have isELIgnored="true" set somewere in the JSP file? Like this:
<%# page isELIgnored="true" %>
Or maybe in web.xml:
<el-ignored>true</el-ignored>
It should be false by default, but if you use servlet version older than 2.4 then the default is true, so in that case you would need to set it to false in web.xml:
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<el-ignored>true</el-ignored>
</jsp-property-group>
</jsp-config>
You have version 3.1 in dependencies, but in web.xml file 2.3 version is used. To use Servlet 3.1 try to change your web.xml into:
<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">
rest of the TAGs
</web-app>
Also remove:
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
(it's for 2.3 version)
Related
I've been building an application to move google analytics data from Bigquery's datasets to Google Storage.
My intention is to deploy a web application on Google App Engine and set up a few cron jobs to call the right URL's periodically and then have some servlets to manage those requests.
I am developing on eclipse and using the App Engine plugin provided by Google here https://developers.google.com/eclipse/ .
Using this plugin, I have created a "Maven-based Google App Engine Standard Java Project", containing a simple java servlet HelloAppEngine.java, a basic index.jsp page and a class with a simple method. Here's the code for this three, the web.xml and the appengine-web.xml as well.
HelloAppEngine.java:
import java.io.IOException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloAppEngine extends HttpServlet {
#Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException {
response.setContentType("text/plain");
response.getWriter().println("Hello App Engine!");
}
}
index.jsp:
<!DOCTYPE html>
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<%# page import="bigqueryexport.HelloInfo" %>
<html>
<head>
<link href='//fonts.googleapis.com/css?family=Marmelad' rel='stylesheet' type='text/css'>
<title>Hello App Engine Standard</title>
</head>
<body>
<h1>Hello App Engine -- Standard!</h1>
<p>This is <%= HelloInfo.getInfo() %>.</p>
<table>
<tr>
<td colspan="2" style="font-weight:bold;">Available Servlets:</td>
</tr>
<tr>
<td><a href='/hello'>The servlet</a></td>
</tr>
</table>
</body>
</html>
And here's the web.xml:
<?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"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>HelloAppEngine</servlet-name>
<servlet-class>bigqueryexport.HelloAppEngine</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloAppEngine</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
And finally, the appengine-web.xml:
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<threadsafe>true</threadsafe>
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>
</appengine-web-app>
To this point, i have written not a single line of code and everything works just fine when I deploy this code to Google Platform. Now, according to https://cloud.google.com/appengine/docs/standard/java/config/cron , by just adding a cron.xml file with the right code and deploying the app again, it should be ready to go. Here's the cron.xml that I have created in the same folder where appengine-web.xml is.
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/hello</url>
<description>test cron job</description>
<schedule>every 3 minutes</schedule>
</cron>
</cronentries>
According to the documentation provided above, this should create the scheduled task that does a get request to my servlet every 3 minutes, yet when I deploy the application again, the cron job won't show on the google platform interface, and it won't work every 3 minutes either.
What am I missing here?
Thanks
PS: This is what the compilation outputs on the console.
Beginning interaction for module default... 0% Scanning for jsp files.
0% Compiling jsp files. abr 04, 2017 4:34:24 PM org.apache.jasper.JspC
processFile INFORMACI�N: Built File: \index.jsp warning: [options]
bootstrap class path not set in conjunction with -source 1.7 Success.
Temporary staging for module default directory left in
D:\somepath
You are about to deploy the following services:
- project-id/default/20170404t163438 (from [D:\somepath\app.yaml])
Deploying to URL: [https://project-id.appspot.com]
Beginning deployment of service [default]... File upload done.
Updating service [default]... .............................done.
Deployed service [default] to [https://project-id.appspot.com]
You can stream logs from the command line by running: $ gcloud app
logs tail -s default
To view your application in the web browser run: $ gcloud app browse
Just FYI as a work around you can find the cron.yaml file in your {buildOutputPath}/appengine-staged/WEB-INF/appengine-generated/ directory.
gcloud app deploy --project=yourprojectname cron.yaml will deploy the cron jobs to your project.
Ensure that you are using at least the 1.0.2 version of the Cloud Tools for Eclipse plugin which contains the fix for this problem. For reference: the relevant issue: https://github.com/GoogleCloudPlatform/google-cloud-eclipse/issues/1676 and the relevant PR: https://github.com/GoogleCloudPlatform/google-cloud-eclipse/pull/1690
I am using JSF 2.2 taglibs but Eclipse is displaying the following warning message:
Can't find facelet tag library for uri http://xmlns.jcp.org/jsf
What bugs me is that I've faced this issue before and it was related to classpath JARs, but now it is only affecting JSF 2.2 tag libs.
Taglib xmlns:h="http://xmlns.jcp.org/jsf/html" is working fine, the warning is shown to JSF 2.2 specifics like "/jsf" and "/jsf/passthrough". Here is an image showing warnings for JSF 2.2. tag libs, but prior namespaces are loaded correctly.
I have tried to solve the issue with help of posts like this but none of the procedures (clean, restart, close/open, validate, etc) have worked for me.
Dependencies for JSF (derived from WildFly 10.1 pom.xml):
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.13</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.13.SP1</version>
<scope>provided</scope>
</dependency>
Eclipse info:
Version: Neon.1a Release (4.6.1)
Build id: 20161007-1200
Update
After looking into the taglib files I found no "passthrough" or "friendly markup" reference. So there is no surprise Eclipse won't find it...
There is no file under com.sun.faces.metadata.taglib for Friendly Markup and Passthrough, for both Glassfish and JBoss implementations.
The question now is where should these files be?
Update: opened issue WFLY-9579
It seems that the taglib files are missing from the implementation JARs, for both Glassfish and JBoss projects. I hope to be wrong but I found no other explanation.
I've posted a thread so this behavior can be investigated.
https://developer.jboss.org/thread/274046
Workaround
To stop the IDE from warning simply create empty taglibs files and associate to the web.xml. Files should go under /WEB-INF/ and have the appropriate extension taglib.xml.
The JSF implementation will behave normally and should process the facelets correctly.
friendly_markup.taglib.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<facelet-taglib 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-facelettaglibrary_2_2.xsd"
version="2.2">
<namespace>http://xmlns.jcp.org/jsf</namespace>
</facelet-taglib>
passthrough.taglib.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<facelet-taglib 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-facelettaglibrary_2_2.xsd"
version="2.2">
<namespace>http://xmlns.jcp.org/jsf/passthrough</namespace>
</facelet-taglib>
web.xml
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/passthrough.taglib.xml;/WEB-INF/friendly_markup.taglib.xml</param-value>
</context-param>
Here is what it looks like. Now the warnings are gone (and my OCD is calm again). I would like to try and make JAR dependency for it, if I find some spare time.
I am trying to render JSP in a Spring 3.2 using annotation driven configuration, but the JSP renders as a string and is not evaluated.
I am using the maven jetty plugin to run the webapp in development. So it seems as if everything should "just work".
The dependencies I am including to use JSP are
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
The bean to configure JSP is
#Configuration
public class WebAppConfiguration {
#Bean
public InternalResourceViewResolver internalResourceViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/views/");
resolver.setSuffix(".jsp");
return resolver;
}
}
The controller is pretty straight forward
#Controller
public class RootController {
#RequestMapping(value = "/login")
public String login() {
return "login";
}
and the JSP is also pretty easy
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head></head>
<body>
<%= "Hello World" %>
${ "Hello World" }
<form name="auth" action="<c:url value='j_spring_security_check' />" method="POST">
<label>Username: <input type="text" name="j_username"></label>
<label>Password: <input type="password" name="j_password"></label>
<input type="submit" value="Submit"/>
</form>
</body>
</html>
As you can see from the image the JSP is not being evaluated. Is there anything I need to do to tell JSP to be evaluated when rendered.
Edit 1
So just for a little extra information I used the Resthub archetype resthub-mongodb-backbonejs-archetype to bootstrap this project, which uses a WebAppInitializer rather than the older web.xml, and it uses new annotation driven beans rather than the xml beans.
EDIT 2
I have been smashing my head on this for all to long so I put the project on github https://github.com/austinbv/calendar/. Since I do not know what is important and what is not.
Thanks for the help
#austinbv Please use the SPRING LINK to check the setup. (As #Rohit has pointed you above - the missing piece)
I had the same problem when using spring boot. Adding these dependencies to the project pom.xml resolved the issue:
<dependency>
<groupId>tomcat</groupId>
<artifactId>jasper-compiler</artifactId>
<version>5.5.23</version>
</dependency>
<dependency>
<groupId>tomcat</groupId>
<artifactId>jasper-runtime</artifactId>
<version>5.5.23</version>
</dependency>
<dependency>
<groupId>tomcat</groupId>
<artifactId>jasper-compiler-jdt</artifactId>
<version>5.5.23</version>
</dependency>
The above given issue fixed for me after making following change in the "web.xml"
The spring servlet needs to be the default servlet. ie mapped to / and not /*.
Ref link: https://code-examples.net/en/q/b49ce1
You need to specify the appropriate view class
public InternalResourceViewResolver internalResourceViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setViewClass(org.springframework.web.servlet.view.JstlView.class);
resolver.setPrefix("/views/");
resolver.setSuffix(".jsp");
return resolver;
}
I do not know how much actual will be my answer, but I had exactly the same issue (Spring + boot + maven + tomcat).
I solved it by removing the scope-provided from tomcat.embed dependence. So, my dependence now looks like this:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
Because JSP does not obey MVC pattern :P
So I used to configure my taglib like that:
<jsp-config>
<taglib>
<taglib-uri>myTags</taglib-uri>
<taglib-location>/WEB-INF/lib/mylib-2.0.1.jar</taglib-location>
</taglib>
</jsp-config>
But now mylib-2.0.1.jar is a maven dependency, so of course it is NOT on /WEB-INF/lib.
How do I do to configure my taglib so I can do that in my JSPs:
<%# taglib uri="myTags" prefix="mt" %>
EDIT1: To clafiry, the taglib.tld is inside the META-INF inside the jar so you can access the tld by referencing the jar itself. That's a convenient way to distribute your taglib along with the web application framework jar.
EDIT2: When we deploy the webapp, the jar will be in the WEB/INF/lib. But during development, inside eclipse, using m2eclipse, the jar will NOT. So eclipse complains it cannot find the taglib no where, because the jar is not there and I cannot reference my jar in the web.xml.
You do not need to configure anything in web.xml, if the taglib is in \META-INF\taglib.tld inside your jar, it is automatic, Tomcat already recognizes.
You can use the jsp :
<% # Taglib prefix = "my" uri = "http://www.mytags.com/"%>
If you add in your POM the taglig dependency, it will be added in the WEB-INF/lib directory of your webapp.
<dependency>
<groupId>yourTageLib</groupId>
<artifactId>mylib</artifactId>
<version>2.0.1</version>
<scope>compile</scope>
</dependency>
could you please explain how to set the skin for primefaces 1.1 ..
you can try to add
<h:head>
<link type="text/css" rel="stylesheet"
href="#{request.contextPath}/themes/redmond/skin.css" />
</h:head>
to your page and
<context-param>
<param-name>primefaces.skin</param-name>
<param-value>none</param-value>
</context-param>
to web.xml
From http://www.primefaces.org/themes.html:
Installing Themes
Applying a theme from Theme Gallery to
your PrimeFaces project is very easy,
you just need to download the theme
jar, add it your classpath and
configure PrimeFaces to use it.
1) You can either download the theme
manually from this page or using maven
via;
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>aristo</artifactId>
<version>1.0.0</version>
</dependency>
2) Next step is setting
primefaces.THEME parameter with the
theme name, you can also use an EL
expression for dynamic themes. view
plaincopy to clipboardprint?
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>aristo</param-value>
</context-param>
That's it!
I'm currently facing a problem like this, bhut have no real solution for that yet...