Apache tomcat error (no from eclipse or xampp tomcat) - java

I have a problem converting from .docx to .pdf with the Documents4j library, which only happens when I run the application from apache tomcat installation.
However, if the application is executed with Eclipse or XAMPP apache tomcat works correctly.
I have tried Windows 10, Windows 7 and Windows Server 2012 with apache tomcat 8 and 8.5 but the problem persist.
Eclipse or XAMPP do "something" when running apache tomcat that makes it work correctly
jsp:
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%# page import="com.documents4j.api.IConverter,
com.documents4j.job.LocalConverter,
com.documents4j.api.DocumentType,
java.io.File" %>
<!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>Insert title here</title>
</head>
<%
IConverter converter = LocalConverter.make();
converter.convert(new File("C:\\test\\test.docx")).as(DocumentType.DOCX).to(new File("C:\\test\\test.pdf")).as(DocumentType.PDF).execute();
%>
</body>
</html>
Dependencies:
<dependencies>
<!-- Local dependencies -->
<!-- https://mvnrepository.com/artifact/com.documents4j/documents4j-local -->
<dependency>
<groupId>com.documents4j</groupId>
<artifactId>documents4j-local</artifactId>
<version>1.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.documents4j/documents4j-transformer-msoffice-word -->
<dependency>
<groupId>com.documents4j</groupId>
<artifactId>documents4j-transformer-msoffice-word</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
Error:
org.apache.jasper.JasperException: com.documents4j.throwables.ConverterException: Conversion failed for an unknown reason
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:565)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:481)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
com.documents4j.throwables.ConverterException: Conversion failed for an unknown reason
com.documents4j.job.AbstractFutureWrappingPriorityFuture.run(AbstractFutureWrappingPriorityFuture.java:90)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)

You can try to specify an explicit base folder for the converter. Application containers often define an implicit temporary folder that is different from the default temporary folder, maybe your setup forbids execution of scripts from within this folder what might cause your troubles. You can check the temporary folder by checking the java.io.tmpdir property at runtime.
As another problem, make sure that your base folder does not contain any spaces. Please update to 1.0.3, too, where the update contains improved handling of such spaces. Maye Tomcat is installed in "Program Files" which might be the problem.

Related

Struts 1.x taglibs compatibility issues with jstl tags

I decided to post this question after 3,5 weeks of blocking and i'm really in need of someone's help.
The problem is with the compatibility and coherence of different taglibs, for budget reason we couldn't migrate the IHM and Web framework of the application which is struts 1.2
The problem after my analysis results in incompatibility between struts-nested taglib with it's possible values and jstl tags value.
for example :
The following code doesn't work
<nested:iterate property="listeSupportsStructuresPlPg">
<c:choose>
<c:when test="${listeSupportsStructuresPlPg.code eq 'PL' && !listeSupportsStructuresPlPg.testOfNajah}">
<div class="row">
<div class="niveauPLPG">
<b>Poche libre </b>
</div>
</div>
</c:when>
</c:choose>
</nested:iterate>
As you can see the c:when test attribute uses the property listeSupportsStructuresPlPg provided by the nested:iterate tag, when i replace the nested:iterate with c:forEach it works just fine but it crashes later when i wanna do another thing + there are 100s occurences of such code and it will be almost impossible to resolve. it's a very difficult situation i'm facing these times, especially that i have tried everything possible to make this incompatible tags work with each other but no good results was obtained.
Project Context: We were migrating from Web-Logic Server To WilfFly 10.0.0.FINAL, before Migration i'd like to say that this isssue never existed.
Solutions i tried before posting this question
I replaced the local c.tld with
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
I replaced nested:iterate with c:forEach but it didn't work
I replaced strus-nested.tld with many definitions but it didn't work
I upgraded the version from 1.2 to 1.3 until 1.x terminated
I tried to do change the value of the conditions by evaluating booleans instead of lists but it worked only in some places and i couldn't find why.
that's all i can remember, but i can assure you that i tried a lot of possible fixes but no results.
I solved it after a deep analysis guy,
Here are the steps that i followed so i can make this page work
Step 1: Changing the way we load the TLDs
Previously they were loaded locally from WEB-INF folder, i changed it so it can be loaded directly from the appropriate jars.
<%# taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%# taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%# taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%# taglib uri="http://struts.apache.org/tags-nested" prefix="nested" %>
<%# taglib uri="/WEB-INF/cgit.tld" prefix="cgit" %>
<%# taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%# taglib uri="http://java.sun.com/jstl/xml" prefix="x" %>
Step 2: Dropping all local TLDs
Step 3: Struts framework version upgrade
Previously they core version was at 1.2.8, The current version is 1.3.10
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-core</artifactId>
<version>1.3.10</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-taglib</artifactId>
<version>1.3.10</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-tiles</artifactId>
<version>1.3.10</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-tiles</artifactId>
<version>1.3.10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-extras</artifactId>
<version>1.3.10</version>
</dependency>
and i changed a little bit the nested:iterate by adding the element id which represents the same thing as var represents in c:forEach
<nested:iterate id="row" property="listeSupportsStructuresPlPg">
<c:out value="${row.****}"/>
</nested:iterate>
This way the jstl c tags can understand the nested:iterate property element.
Just for information, u skip one if these steps, nothing works
Thanks for those whom tried to help.
I don't think your c tags don't know how to access the Struts value stack, so they don't know what listeSupportsStructuresPlPg is. Use the struts equivalent of <c:choose>. In Struts 2, this is <s:if>. I'm not sure exactly what it is in Struts 1, but probably something similar.

Cannot resolve taglib with uri in Intellij IDEA

By looking at the tutorial series JSP, Servlets and JDBC for Beginners: Build a Database App on Udemy done by Chad Darby and with the help of BalusC answer I wrote the following code in Intellij IDEA
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%--To use JSTL core tags we need to import the following URL with prefix--%>
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<%
// need to define a sample array
String cities[]={"City1","City2","City3","City4"};
// to use JSTL tags they have a to be a part of an attribute, either in the scope of the pageContext, session or application
pageContext.setAttribute("myCities",cities);
%>
<body>
<%-- for printing them in for each loop--%>
<c:forEach var="cityName" items="${myCities}" >
<%-- here we are using JSP expression language as ${...}}--%>
${cityName} <br/>
</c:forEach>
</body>
</html>
and add the JSTL libs under WEB-INF/lib as suggested by both the author of the tutorial (note: tutorial is done on Eclipse IDE) and BalusC answer. The code works fine, but IDEA editor give me
cannot resolve taglib with uri http://java.sun.com/jsp/jstl/core
and
cannot resolve symbol 'c:forEach'
and those lines are in red color as seen in the image
Why is this happening?. Is there any other place to add those libraries in IDEA? Thanks in advance
I got similar kind of message while working with spring based project. I resolved it by adding following dependencies inside pom.xml
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
next open terminal and then do maven clean install
mvn -U clean install

I want to read the parameters of tomcat context.xml

I want to get companyName value which is in context.xml
I am getting null value after writing the code mentioned below
Please help me in getting the value from context.xml. You can even tell other way of getting value from context.xml
NOTE : Don't say to write param in web.xml
Context.xml (Tomcat 7)
<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- The contents of this file will be loaded for each web application -->
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
<!-- Uncomment this to enable Comet connection tacking (provides events
on session expiration as well as webapp lifecycle) -->
<!--
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
-->
<Parameter name="companyName" value="My Company, Incorporated"
override="false"/>
</Context>
JSP(index.jsp)
<%# 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">
<title>Insert title here</title>
</head>
<body>
<%
ServletContext sc= getServletContext();
String testNameValue = sc.getInitParameter("companyName");
%>
<input type="text" value="<%=testNameValue%>">
</body>
</html>
Output
Updated after implementing the solution given below
Exception comes
Exception
You cannot load that way because context.xml is JNDI resource. Please try the following approach:
Tomcat (context.xml)
<Parameter name="companyName" value="My Company, Incorporated" override="false"/>
Java Side
InitialContext context = new InitialContext();
Context xmlNode = (Context) context.lookup("java:comp/env");
String companyName = (String) xmlNode.lookup("companyName");
Spring Side
HomeController.java
#Controller
#RequestMapping("/")
public class HomeController {
#Autowired
private ServletContext servletContext;
#RequestMapping(method=RequestMethod.GET)
public ModelAndView index(ModelAndView mav) throws Exception {
String companyName = servletContext.getInitParameter("companyName");
mav.setViewName("home/index");
mav.addObject("companyName", companyName);
return mav;
}
public void setServletContext(ServletContext servletContext) {
this.servletContext = servletContext;
}
}
View Side
index.jsp
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Home</title>
</head>
<body>
<c:out value="${companyName}"/>
</body>
</html>
The above example has proven successful on my end. My script can read from context.xml file at runtime as shown.
<Environment name="companyName" value="My Company, Incorporated"
type="java.lang.String" override="false"/>
worked better for me than Parameter because the latter was throwing
javax.naming.NameNotFoundException: Name [companyName] is not bound in this Context. Unable to find [companyName]. when trying to get the value using String companyName = (String) xmlNode.lookup("companyName");

Struts 2 could not find a result for success returned from an action

I'm not a native English speaker, so my apologizes if I made some idiomatic mistake. I'm completely new on Struts2.
I developed a web project that contains 3 JSP pages, a deployment descriptor (web.xml), a struts configuration file (struts.xml) with 2 actions configured inside (an action named index and an action named welcome) and 1 class that implements the action logic for welcome action. When I try the index action it works perfectly but if I call the welcome action in the URL (welcome.action) I get the following error
Struts Problem Report
Struts has detected an unhandled exception:
Messages:
No result defined for action actions.WelcomeAction and result success
com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:275)
...
Now I give you more information about the project and environment:
Development Environment
OS: Mac OS X 10.10.3
JRE: 1.8.0_20
IDE: NetBeans 7.4
App Server: GlassFish 4.0
Server Location: localhost:8080
Context Path: /AppStruts2Example
URL Project: http://localhost:8080/AppStruts2Example/
Web Project Development Information
Java EE Version: 7
Struts2 Version: 2.3.15
Code is described below
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" 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">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
struts.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.configuration.xml.reload" value="true" />
<!-- Configuration for the default package. -->
<package name="default" extends="struts-default">
<action name="index">
<result>/WelcomeFromIndexAction.jsp</result>
</action>
<action name="welcome" class="actions.WelcomeAction">
<result name="success">/WelcomeFromWelcomeAction.jsp</result>
</action>
</package>
</struts>
actions.WelcomeAction.java
package actions;
import com.opensymphony.xwork2.ActionSupport;
public class WelcomeAction extends ActionSupport{
#Override
public String execute(){
System.out.println("Inside of execute method in WelcomeAction.");
System.out.println("Result: " + SUCCESS);
return SUCCESS;
}
}
index.jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Index JSP</title>
</head>
<body>
<h1>Welcome to index.jsp!</h1>
</body>
</html>
WelcomeFromIndexAction.jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Index Action</title>
</head>
<body>
<h1>Welcome From Index Action</h1>
<br />
<h3>Current Page: WelcomeFromIndexAction.jsp</h3>
</body>
</html>
WelcomeFromWelcomeAction.jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome Action</title>
</head>
<body>
<h1>Welcome From Welcome Action</h1>
<br />
<h3>Current Page: WelcomeFromWelcomeAction.jsp</h3>
</body>
</html>
Project works fine when:
I write directly the URL of anyone JSP on the browser
I invoke the index action as you can see below: /index.action or /index -> both redirect me to WelcomeFromIndexAction.jsp
Project fails when:
I invoke the welcome action as you can see below: /welcome.action or /welcome -> both shows me a web page with Struts Problem Report like described above
I thought it could be a problem with GlassFish Server, so I mounted a Debian on a VM and I installed a Tomcat 7 there. My next step was deploy the web application whit "Clean and Build" from NetBeans. It generated me a WAR file that I deployed into Tomcat 7 but I got the same problem. After this disappointing I disabled the Debian VM (Tomcat 7) and I come back to work with GlassFish 4.0
As you can see in WelcomeAction.java, it has a println statement within execute method. When I invoke welcome action on the browser, I can see that Struts effectively calls that method, the lines are printed on the output and after this call, when Struts2 has to process the Result then show me the error. This confirm me that Struts2 is not finding the result not the action, but I don't know why.
I tried configuring the filter dispatcher with old and new version of filter (FilterDispatcher/StrutsPrepareAndExecuteFilter). With both i get same problem.
I tried configuring the welcome action in struts.xml exactly the same index action (practically by default) but doesn't work too. Only index action run fine.
I tried configuring the welcome action in struts.xml of many many ways, but nothing works.
So, here i am, needing someone help me. I appreciate your answers.
Note: Stackoverflow doesn't allow me post image because i'm new. So, I uploaded an important print screen to my dropbox. https://dl.dropboxusercontent.com/u/101502868/NetBeans%20Struts2%20Error.png
At this print screen you can see the libraries added, execution of execute method, the customized print lines and start of Struts error's.
Thank's.
make entry in struts.xml with custom method in action class named editUser so that control dirctly goes to that perticuler method and handle the result accordingly your logic
<action method="editUser" name="editUser" class="com.action.EditUserAction">
<result name="true">/jsp/editUser.jsp</result>
<result name="false">jsp/index.jsp</result>
</action>
And add custom method in your class instead of override execute method
class EditUserAction extendes ActionSupport{
public String editUser(){
String status = "false";
/**
do your buisness logic
*/
return status;
}
}
After doing same if still the issues is persist then check your configuration carefully
The best way to fix this issue is using Maven to create your project and manage all dependencies you could need. That was the only solution that works to me.
Here is an official guide to create a Struts 2 Web Application using Maven (very simple example): http://struts.apache.org/docs/create-struts-2-web-application-using-maven-to-manage-artifacts-and-to-build-the-application.html
If you don't have installed Maven is OS X and you don't know how to install it, then follow the next steps to install it:
Download Maven (This example uses Maven 3.3.3. The name of the compressed file is apache-maven-3.3.3-bin.tar.gz): http://maven.apache.org/download.cgi
Unpack the downloaded file (This example assumes that the downloaded file is located in /Users/YourUser/Downloads/). After unpack, a new directory will be created with the same name and path of your maven file downloaded. (In this example: /Users/YourUser/Downloads/apache-maven-3.3.3/)
Open a Terminal
Move your maven directory to your home directory using this command:
mv ~/Downloads/apache-maven-3.3.3/ ~/
Now, you have to edit the file .bash_profile located on your home directory (~/.bash_profile). To edit it, we'll use vi commando as you can see below:
vi ~/.bash_profile
Once opened you must press i to edit it
Now you can edit the file, so you have to write the following:
export JAVA_HOME=$(/usr/libexec/java_home)
export MAVEN=$HOME/apache-maven-3.3.3/bin
Close the terminal and open it again. That's all, Maven should be already installed. Use the following command to verify that Maven is working:
mvn -version
If you see the information about Maven, Java and OS X that you are using it's because Maven is working fine.

Why isn't my GWT web application running properly?

I'm going through the book: GWT in Action. On chapter I'm working through the very first hello world application. It's all in development mode.
My issue is that the label in my .java file is not showing up when I open the URL webpage. There is nothing being displayed versus the Label("Hello World!") appearing.
EDIT: When at the displayed webpage, I pressed F12 in google chrome to see if I could find anything weird. Got the error: Failed to load resource: the server responded with a status of 404 (Not Found)
HelloWorld.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.6.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.6.0/distro-source/core/src/gwt-module.dtd">
<module>
<inherits name="com.google.gwt.user.User" />
<source path="client" />
<entry-point class="com.example.gwt.client.HelloWorld"></entry-point>
</module>
HelloWorld.java
package com.example.gwt.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
public class HelloWorld implements EntryPoint {
#Override
public void onModuleLoad() {
RootPanel.get().add(new Label("Hello World!"));
}
}
HelloWorld.html
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>HelloWorld</title>
<script type="text/javascript" language="javascript" src=".nocache.js"></script>
</head>
<body>
<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
</body>
</html>
My console is displaying this after I run it as a web application:
[WARN] Server class 'org.eclipse.jetty.servlet.listener.ELContextCleaner' could not be found in the web app, but was found on the system classpath
[WARN] Adding classpath entry 'file:/C:/Users/Qs/Desktop/eclipse/plugins/com.google.gwt.eclipse.sdkbundle_2.6.0/gwt-2.6.0/gwt-dev.jar' to the web app classpath for this session
For additional info see: file:/C:/Users/Qs/Desktop/eclipse/plugins/com.google.gwt.eclipse.sdkbundle_2.6.0/gwt-2.6.0/doc/helpInfo/webAppClassPath.html
If you don't specify the rename-to in your gwt.xml as shown below then by default GWT places the generated nocache.js under war directory by the name of location of gwt.xml followed by its name as shown in below snapshot.
<module rename-to="xyz">
For more info have a look at gwt-module dtd.
Please have a look Defining a module and Renaming modules
There are two ways to solve this issue:
define rename-to in gwt.xml that is more preferable over second solution
gwt.xml
<module rename-to="hello">
html
<script type="text/javascript" language="javascript" src="hello/hello.nocache.js"></script>
use default way
html
<script type="text/javascript" language="javascript" src="com.example.gwt.HelloWorld/com.example.gwt.HelloWorld.nocache.js"></script>
Here is a snapshot to make it more clear
Change the src attribute of the script tag in HelloWorld.html to
src="com.example.gwt.client.HelloWorld/com.example.gwt.client.HelloWorld.nocache.js"
If that still doesn't work, run the GWT compiler and look at the files it generates to determine the exact name of the *.nocache.js file.

Categories

Resources