How to use jsp files of another project in eclipse - java

I am developing a web application using spring and hibernate in multiple modules.
And i want to use a module which is another project into different project.
But i am unable to use jsp files of that module.
Actually i have 2 projects named profile and SecondProject. And i have a jsp file named Insert.jsp in profile project. And Insert2.jsp file in SecondProject. Now i want to include Insert2.jsp file into Insert.jsp.
So how can i do this please suggest me.
here is the code of Insert.jsp file
<form action="/Profile/sendData" method="POST">
Name: <input type="text" name="name" />
<input type="submit" value="submit" />
</form>
<%#include file="Insert2.jsp" %>

You can use JSTL <c:import> Tag in Profile Project's Insert.jsp like this :
<c:import url="http://localhost:8080/SecondProject/insert2.jsp"/>
Note: Don't forgot to add jstl jar in classpath and also below line:
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

Related

CSS JS and Links not loading when deploy Spring boot as war in Tomcat

I have a Spring boot web application, it works fine when running as executable jar, but when I build as war and deploy to Tomcat, the css, js files are not loading and looking into further, I found out all links are pointing to root context path "/", I tried changing base href = "./" this fixed the problem of loading css and js, but I need to do that in lot of pages.
Also the links in <a> still points to root context path and to make this work I need prefix'./' . Below are my code snips,
CSS and JS link
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/signin.css" rel="stylesheet">
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
Tag
<a class="topHeader" href="/activateAccount"></a>
Is there a shortcut to fix this problem or should I change <base href> and <a href> in all the pages? Any help is highly appreciated.
There is no short cut or quick fix for this, I removed "/" in links in all anchor tags and that worked for me.
Example
<a href="/resetPassword" style="float: right;">
changed to
<a href="resetPassword" style="float: right;">

Enable JSP in Tomcat

I have setup Tomcat version 7.0.65 and I am trying to open a .jsp file. What I get as a result is something in the line of:
<%# include file="header.jsp" %>
<div id="body-0" class="body">
<div class="body-content">
<h1 class="title solid">What is Delivery IQ?</h1>
<div class="content">
<iframe width="853" height="480" src="https://www.youtube.com/embed/U6P8GxPCbyc" frameborder="0" allowfullscreen></iframe>
</div>
</div>
</div>
And not the actual site. Does anyone know what do I have to do in order to get it working?
You have to compile all the application and deploy to the Tomcat. Please read this link.
Also you could read enter link description here this could make it clear in first of the chapters.
Without RTFM you are just blindly clicking.

Java (IntelliJ Idea) - import class fail

I have a jsp page that imports a class from another module and package.
<%# page language="java" import="login.UserLogin" %>
<%# page contentType="text/html; charset=windows-1251" %>
<html>
<head>
<title>
Page title
</title>
</head>
<body>
<%-- Form to initiate POST --%>
<FORM name="test_form" method="post">
<INPUT type="submit" name="submit" value="Make Post"><BR>
</FORM>
</body>
</html>
I've corrected oll the dependances in IDE, but still get an error log:
org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.index_jsp
The imported class is empty, so there are no further dependances.
Your JSP's are internally compiled to a servlets called [your_jsp]_jsp.java and your IDE is saying that it cannot find that compiled class.
Your problem is that your project is not compiled / not deployed in the server. Or maybe you have not well configured the output directory... I don't know, I don't use intelliJ...
Found! Error in Tomcat deployment config - it referenced to source folder instead of artifact

There are no changes reflected on deploying the theme in liferay 6.1.1

I am a newbie to liferay CMS. I am developing a theme in liferay 6.1.1. my problem is when i am making any changes to the theme it doesnt get reflected after deploying it.
Please check if i am in the right flow:
Firstly new --> liferay project --> selected theme
Deployed nthe theme which created the -diffs folder and the remaining all
folders in the docroot folder inside the theme.
Copied the portlet_normal.vm from the template folder from my theme and made
changes.
Pasted portlet_normal.vm in my theme inside the docroot(folder) --> _diffs(folder) --> templates(folder).
Redeployed the theme but there were no changes reflected.
My portlet_normal.vm file is:
<!DOCTYPE html>
#parse ($init)
<html class="#language("lang.dir")" dir="#language("lang.dir")" lang="$w3c_language_id">
<head>
<title>$the_title - $company_name</title>
$theme.include($top_head_include)
</head>
<body class="$css_class">
$theme.include($body_top_include)
#if ($is_signed_in)
#dockbar()
#end
<div id="wrapper">
#language("skip-to-content")
<header id="banner" role="banner">
<div id="heading">
<h1 class="site-title">
<a class="$logo_css_class" href="$site_default_url" title="#language("go-to") $site_name">
<img alt="$logo_description" height="$site_logo_height" src="$site_logo" width="$site_logo_width" />
</a>
#if ($show_site_name)
<span class="site-name" title="#language("go-to") $site_name">
$site_name
</span>
#end
</h1>
<h2 class="page-title">
<span>$the_title</span>
</h2>
</div>
#if (!$is_signed_in)
$sign_in_text
#end
#if ($has_navigation || $is_signed_in)
#parse ("$full_templates_path/navigation.vm")
#end
</header>
<div id="content">
**/*<nav class="site-breadcrumbs" id="breadcrumbs">
<h1>
<span>#language("breadcrumbs")</span>
</h1>
#breadcrumbs()
</nav>*/**
#if ($selectable)
$theme.include($content_include)
#else
$portletDisplay.recycle()
$portletDisplay.setTitle($the_title)
$theme.wrapPortlet("portlet.vm", $content_include)
#end
</div>
<footer id="footer" role="contentinfo">
<p class="powered-by">
#language("powered-by") Liferay
</p>
</footer>
</div>
$theme.include($body_bottom_include)
</body>
$theme.include($bottom_include)
</html>
Actually i want to hide the breadcrumbs getting displayed in the home page. so i have commented that particular portion in portlet_normal.vm
Any help regarding this will be appreciated , i am completely stuck in this.
You have two possibilities:
If you are developping, you can set the portal in dev mode adding
include-and-override=portal-developer.properties into your portal-ext.properties which should be under the portal root.
If you are in production this option should be disabled and you should check the following
Try to open the XML file build-common-theme.xml under the themes folder in your SDK and remove all the preservelastmodified="true" (or set them to false).
preservelastmodified, when true will not update the files timestamp in your theme project. Therefore, your application server will not detect the changes and redeploy the theme.
From step 1 it seems that you are using Eclipse to create Liferay theme project. Whenevr you create the project you will get
Now all you need to do is, change the files within the _diffs directory and build the theme with ant file build.xml, rest will be taken care by the build file. I am not sure why steps 3 and 4 required.
If the problem still exists, couple of points to look at are :
velocity.engine.resource.manager.cache.enabled=false
set this property in your portal-ext.properties and restart the server.

Jetty 7 hightide distribution, JSP and JSTL support

I've been struggling with Jetty 7 and its support for JSP and JSTL.
My JSP file:
<%# page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<head>
<title>blah</title>
</head>
<body>
<table id="data">
<tr class="columns">
<td>Hour</td>
<c:forEach var="campaign" items="${campaigns}">
<td>${campaign}</td>
</c:forEach>
</tr>
<c:forEach var="hour" items="${results}">
<tr>
<td class="hour">${hour.key}</td>
<c:forEach var="campaign" items="${campaigns}">
<td>${hour[campaign]}</td>
</c:forEach>
</tr>
</c:forEach>
</table>
</body>
</html>
The JSP portions above work as expected. JSTL, however, does not. The campaigns and results variables are request attributes set by a servlet.
I get the following errors:
WARN: ... compiler.TagLibraryInfoImpl: Unknown element (deferred-value) in attribute
WARN: ... compiler.TagLibraryInfoImpl: Unknown element (deferred-value) in attribute
WARN: ... compiler.TagLibraryInfoImpl: Unknown element (deferred-value) in attribute
ERROR: ... javax.servlet.ServletException: java.lang.AbstractMethodError: javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext;
I am not bundling any jar files into my .war file deployed to jetty.
The version of jetty I'm using is: jetty-hightide-7.0.1.v20091125
The classpath:
/usr/local/jetty/lib/jetty-xml-7.0.1.v20091125.jar:/usr/local/jetty/lib/servlet-api-2.5.jar:/usr/local/jetty/lib/jetty-http-7.0.1.v20091125.jar:/usr/local/jetty/lib/jetty-continuation-7.0.1.v20091125.jar:/usr/local/jetty/lib/jetty-server-7.0.1.v20091125.jar:/usr/local/jetty/lib/jetty-security-7.0.1.v20091125.jar:/usr/local/jetty/lib/jetty-servlet-7.0.1.v20091125.jar:/usr/local/jetty/lib/jetty-webapp-7.0.1.v20091125.jar:/usr/local/jetty/lib/jetty-deploy-7.0.1.v20091125.jar:/usr/local/jetty/lib/jetty-servlets-7.0.1.v20091125.jar:/usr/local/jetty/lib/jsp/ant-1.6.5.jar:/usr/local/jetty/lib/jsp/core-3.1.1.jar:/usr/local/jetty/lib/jsp/jetty-jsp-2.1-7.0.1.v20091125.jar:/usr/local/jetty/lib/jsp/jsp-2.1-glassfish-9.1.1.B60.25.p2.jar:/usr/local/jetty/lib/jsp/jsp-api-2.1-glassfish-9.1.1.B60.25.p2.jar:/usr/local/jetty/resources:/usr/local/jetty/lib/jetty-util-7.0.1.v20091125.jar:/usr/local/jetty/lib/jetty-io-7.0.1.v20091125.jar
Any help would be greatly appreciated.
Thanks in advance,
Lior.
With Jetty 8, the situation is a bit different, in case this helps anyone.
For JSTL 1.2, rather surprisingly, the taglib has to be:
<%# taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
with JSTL 1.2 from (mavenishly):
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
I can't really explain why the URL lacks 'jsp', but it works this way.
tsk... I don;t have privilege to comment. I am using Jetty 7.1.6 and answer provided by bmargulies works.
Basically, changing URI from
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
to
<%# taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
makes taglibs to work in Jetty 7.
-Nishant
The reason why http://java.sun.com/jsp/jstl/core doesn't work is because the code in the Jasper Jsp parser used by Jetty (org.apache.jasper.glassfish:jar:2.2.2.xxx) assumes that that uri is a systemuri (see TldScanner.java) and it will not put any taglibs with this uri in its tablib location cache. I don't know why this assumption is in the code but it is. Seems to be a bug to me.
java.lang.AbstractMethodError: javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext;
This exception basically means that the mentioned method cannot be found in the runtime classpath, while it was available in the compiletime classpath of either the class or one of its dependencies.
This method is introduced in JSP 2.1 which gets hand in hand with Servlet 2.5. Since Jetty 7 is supposed to support Servlet 2.5 and thus isn't the suspect here, the only cause can be that the web.xml is declared as Servlet 2.4 or lower instead of Servlet 2.5. So, to fix this particular problem, you need to declare your web.xml as at least Servlet 2.5. The <web-app> tag should look like this:
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
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"
id="YourWebAppID"
version="2.5">
If that doesn't solve the problem, then the other cause is that the /WEB-INF/lib or even worse the /JRE/lib or /JRE/lib/ext is cluttered with appserver-specific libraries containing an older Servlet API version. E.g. servlet-api.jar from Tomcat or j2ee.jar or javaee.jar from Glassfish, etcetera. You'll need to clean up those classpath folders from any libraries which doesn't belong there, because they get precedence in classloading and will override the appserver's own libraries. Appserver-specific libraries belongs to the appserver in question, not to the webapp or JRE.
That said and apart from the actual problem, the #page attributes language="java" contentType="text/html; charset=utf-8" are all superfluous. The language already defaults to Java and the contentType already defaults to text/html and the charset will already be set to UTF-8 if you set pageEncoding="UTF-8". So the following is already sufficient:
<%#page pageEncoding="UTF-8" %>
Thx for the tip Steve! The bug seems still there, here's a workaround to run at Jetty initialisation. It did the trick for me.
import org.apache.jasper.runtime.TldScanner;
import java.util.Set;
Field field = TldScanner.class.getDeclaredField("systemUris");
field.setAccessible(true);
((Set<?>)field.get(null)).clear();
field.setAccessible(false);

Categories