FKeditor and Spring MVC Maven integration step by step - spring

I want to use Fckeditor in my spring mvc. Could you provide instruction or link to set up step by step?
I did below steps but when I run, 404 not found [/springmvc/fckeditor/editor/fckeditor.html ]is showing.
Could you check me what I am wrong and guide me?
Firstly, as per documentation I added below code in pom.xml.
<dependency>
<groupId>net.fckeditor</groupId>
<artifactId>java-core</artifactId>
<version>2.6</version>
</dependency>
And in web.xml file, I added below code.
<servlet>
<servlet-name>ConnectorServlet</servlet-name>
<servlet-class>
net.fckeditor.connector.ConnectorServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ConnectorServlet</servlet-name>
<url-pattern>
/resources/fckeditor/editor/filemanager/connectors/*
</url-pattern>
</servlet-mapping>
After that I download FCKeditor_2.6.8.zip file and extract in the src/main/resources folder.
In the jsp page, I added taglib, javascript and tag.
<%# taglib uri="http://java.fckeditor.net" prefix="FCK" %>
function FCKeditor_OnComplete(editorInstance) {
window.status = editorInstance.Description;
}
<FCK:editor instanceName="EditorDefault">
<jsp:attribute name="value">This is some <strong>sample text
</strong>. You are using <a href="http://www.fckeditor.net">
FCKeditor</a>.
</jsp:attribute>
</FCK:editor>
But Fckeditor is still not working.
Could you guide me which is wrong?
Thank you,

i have used ckeditor, below are configrations
<dependency>
<groupId>com.ckeditor</groupId>
<artifactId>ckeditor-java-core</artifactId>
<version>3.5.3</version>
</dependency>
in jsp file
<%# taglib prefix="ckeditor" uri="http://ckeditor.com"%>
<script type="text/javascript" src="%=request.getContextPath()%>/common/script/ckeditor/ckeditor.js"></script>
<form:textarea path="body" maxlength="5000" /> <ckeditor:replace replace="body" basePath="../ckeditor/" />
make sure you copy js files also and copy it and specify it in jsp

Related

java.lang.ClassNotFoundException: jakarta.servlet.http.HttpServlet : Spring MVC and Eclipse

I am creating a web application using Spring MVC and Eclipse IDE.
Spring Version- 6.0.3
To configure the project, I followed the following steps-
Added dependencies in pom.xml-
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- Spring MVC Dependency -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>6.0.3</version>
</dependency>
</dependencies>
Added Tomcat Server Runtime to the build path-
Added maven dependencies to deployment assembly-
web.xml- (in WEB-INF folder)
<web-app>
<display-name>Spring MVC Demo</display-name>
<!-- Configure dispatcher servlet -->
<servlet>
<servlet-name>dispatcherservlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherservlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- / means handle all the requests from all urls -->
</web-app>
dispatcherservlet-servlet.xml (in WEB-INF folder)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"
xmlns:p="http://springframework.org/schema/p">
<!-- Enable annotations -->
<context:component-scan base-package="spring-mvc-demo.src.main.java.controller"></context:component-scan>
<!-- View Resolver bean -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
name="viewResolver">
<!-- Inject two properties -->
<!-- Location for pages is given to prefix -->
<property name="prefix" value="/WEB-INF/views/" />
<!-- ending of page is .jsp -->
<property name="suffix" value=".jsp" />
<!-- Example name /WEB-INF/views/hello.jsp (here the name hello will be
given by controller) -->
</bean>
</beans>
Placed index.jsp under views folder in WEB-INF-
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Home Page</title>
</head>
<body>
<h1>This is home page</h1>
<h1>Called by home controller</h1>
<h1>fired for /</h1>
</body>
</html>
Created HomeController.java class in src/main/java/controller
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
#RequestMapping("/home")
public class HomeController {
#GetMapping("/current")
public String home() {
//return the name of the page
System.out.println("Hello this is home URL");
return "index";
}
}
I have created a controller with the url /home/current. On visiting this url I expect to see the desired index.jsp.
Problem-
When I "Run on Server" I get following error-
SEVERE: Allocate exception for servlet [dispatcherservlet]
java.lang.ClassNotFoundException: jakarta.servlet.http.HttpServlet
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1412)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1220)
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
Please help me to find the error in my configuration and the reason I get this error.
I saw several other posts, re-checked my steps but still getting the same error-
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
Based on the first screenshot in your question, you're using Tomcat 9. But for Spring 6 you need a minimum of Tomcat 10. Tomcat 10 is the first to use jakarta.* namespace whereas older versions used javax.* namespace.
Spring 6 (and Spring Boot 3) is the first version to use jakarta.* namespace whereas older versions used javax.* namespace.
So you have 2 options:
Upgrade Tomcat to a minimum of 10.
Or, downgrade Spring to a maximum of 5.
Clearly, option 1 is the recommended way to go in long term.
By the way, Spring 6 requires Java 17 not Java 1.7 as seen in the first screenshot in your question.
See also:
A Java 17 and Jakarta EE 9 baseline for Spring Framework 6
Apache Tomcat Versions
How to properly configure Jakarta EE libraries in Maven pom.xml for Tomcat?

Lucee Not Serving index.cfm By Default

I have a dev machine running Lucee with Tomcat on Mac OS X El Capitan. Lucee is running fine, but when I bring up my dev site, mapped to admin.local, I have to type in "admin.local:8080/index.cfm". For some reason entering the URL as "admin.local:8080" just brings up a 404. Is there something I need to do to get Lucee/Tomcat to serve index.cfm by default?
UPDATE:
The web.xml for Tomcat does include the following:
<servlet-mapping>
<servlet-name>CFMLServlet</servlet-name>
<url-pattern>*.cfc</url-pattern>
<url-pattern>*.cfm</url-pattern>
<url-pattern>*.cfml</url-pattern>
<url-pattern>/index.cfc/*</url-pattern>
<url-pattern>/index.cfm/*</url-pattern>
<url-pattern>/index.cfml/*</url-pattern>
<!-- url-pattern>*.cfm/*</url-pattern !-->
<!-- url-pattern>*.cfml/*</url-pattern !-->
<!-- url-pattern>*.cfc/*</url-pattern !-->
<!-- url-pattern>*.htm</url-pattern !-->
<!-- url-pattern>*.jsp</url-pattern !-->
</servlet-mapping>
In order for your web server to handle the index.cfm files without specifying it in the URL you will need to add that as a default document for your web server. You mentioned you are using Apache, one approach for that web server is to add index.cfm to the DirectoryIndex within the httpd.conf file.
Here is an example of how to do that - https://stackoverflow.com/a/7977774/1636917
I just added index.cfm to welcome file list in web.xml, it helps
<web-app ...
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.cfm</welcome-file>
</welcome-file-list>
</web-app>

How to access css file with Tomcat 6 and Spring 3.0.4

I try to access css file by:
<link rel="stylesheet" href="META-INF/resources/css/style.css" />
Structure:
springhibernate
-META-INF
-recources
-css
-style.css
-img
-WEB-INF
-classes
-jsp
web.xml
application-context.xml
web.xml part:
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
How can I refer to a css file?
The META-INF directory is not accessible using an URL according to the specification. It's purpose is to hold information useful to Java archive tools, xml descriptors, etc.
Create separate top-level directory in your .war file to serve CSS, Javascript, HTML, etc. files.
Note: you can access everything in META-INF in your Java code, using ServletContext's getResource and getResourceAsStream calls. The limititation is that it cannot be referenced with a URL.

serve static resource using spring 3.0.0 and tomcat

I need to expose some static content (xsd files that are required by the wsdl). I cannot use the mvn:resources since it is not available in Spring 3.0.0
I don't have an idea as to where the static content should go. Hope someone can help me.
In my web.xml i have
<servlet>
<servlet-name>Resources</servlet-name>
<servlet-class>org.springframework.web.servlet.ResourceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Resources</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
then in the webapp dir I added a resources dir with the static files.
% ls webapp
index.jsp META-INF resources WEB-INF
can someone tell me where the static content should go.
thanks much.
Dont forget this one aswell:
<!-- Allows for mapping the DispatcherServlet to "/" by forwarding static resource
requests to the container's default Servlet -->
<mvc:default-servlet-handler/>
You wrote
I cannot use the mvn:resources since it is not available in Spring 3.0.0
This is complete wrong!
mvn:resources is avaiable in Spring mvc namespace for version 3.0.0 3.0.4
See the xsd: http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd

Spring MVC - include static files / javascript , css

I have created MVC application.
I want to include js or css file into jsp.
My static files ar under:
- webapp
-js/jquery.js
-WEB-INF|
|
- jsp/*.jsp
My code to include jquery is:
<script type="text/javascript" src="<c:url value="js/jquery.js" />"></script>
and i cant load the js file into view.
I see the logs with info:
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/pool/js/jquery.js] in DispatcherServlet with name 'appServlet'
what means, that MVC try to map url to js file.
I think that there is something with my configuration, but i don't know what.
my web.xml is:
<?xml version="1.0" encoding="UTF-8"?>
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
add this to you confing and modify the location according to your need.
<mvc:resources mapping="/static/**" location="/WEB-INF/static/"/>
see this How to handle static content in Spring MVC?
Change your DispatcherServlet mapping to e.g:
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
Or some other not conflicting url-pattern like *.htm or /controllers/*. Remember that from now on all your controllers will be available only through this pattern.
Now it is intercepting everything in your web application, including .js files, images, etc.
The same thing with hibernateFilter - you don't really need an open Hibernate session when fetching .js files, don't you?
Why not use the simple jsp core ?
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<link rel="stylesheet" type="text/css" href="<c:url value='/resources/css/bootstrap.css'/>" />
Use spring JSTL tags to include external script files or style sheets.
First you should include the the taglib in JSP as follows.
<%# taglib uri="http://www.springframework.org/tags" prefix="spring"%>
Then you can include extenal script file using,
<script type="text/javascript" src="<spring:url value="/js/jquery.js"/>"></script>
I agree with your answer. But in the style.css file declare url that relate to path of image.
--style.css--
.cwt-object0
{
display: block;
left: 2.62%;
margin-left: -1px;
position: absolute;
top: 43px;
width: 64px;
height: 64px;
background-image: url('/resources/images/object0.png');
background-position: 0 0;
background-repeat: no-repeat;
z-index: 0;
}
How to use tag <spring:url></spring:url> in style.css file to see in browser IE/Firefox
--jsp file ---
<link href="<spring:url value="/resources/style.css"/>" rel="stylesheet" type="text/css" media="screen">
add mvc:resources in your config file(*-servlet.xml), you can find it works
I just followed Mkyong Tutorial to place css, js, jquery & image files. Its working for me.
In servlet-context.xml
<!-- Handles HTTP GET requests for /resources/** by efficiently serving
up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/assets/" />
In JSP , import tag library
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
and add like
<link rel="stylesheet" href="<c:url value='/resources/css/custom.css'/>">

Resources