I am currently refactoring a web application that has been around for 13 years. First I updated the dependencies to Java SE 8, Tomcat 7 and JSF 2.2. The next task in the refactoring process is to split the functionalities and the respective frontends into seperate modules.
My goal is that each seperate module, that has a frontend, is responsible for its own routing and servlet mapping. The "Core"-module should direct the traffic to the respective module and let the module serve the desired content.
And that's where I'm facing immense trouble.
An approach to the problem was the following tutorial (in german): https://www.tutorials.de/threads/modularisierbare-web-anwendungen-mit-jee6-web-profile-web-fragments.372772/, which is about web-fragments (web.xml files in modules) that can easily be included in a parent web.xml.
However the core module can't reach the desired files, and I just can't figure out why.
Please take a look at the following files:
pom.xml (excerpt of module 1 (core)):
<dependency>
<groupId>org.myapp</groupId>
<artifactId>myapp-frontendmodul</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
web.xml (excerpt of module 1 (core) web.xml):
<web-app version="2.5" 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/j2ee/web-app_2_5.xsd" metadata-
complete="false">
[...]
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
[...]
Since we just now started the refactoring, a part of the core module is a web app.
The folder structure to the respective files (module 1 (core)):
src.main
java
resources
webapp
newpages
(all views currently are in here)
WEB-INF
web.xml
Folder structure to respective files (module 2):
src.main
java
resources
META-INF
web.xml
webapp
pages
AktuelleSchritteAlle.xhtml
pom.xml (module 2):
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>myapp-production</artifactId>
<groupId>org.myapp</groupId>
<version>3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<name>My App - Frontend Modul</name>
<artifactId>myapp-frontendmodul</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
web.xml (module 2):
<web-fragment 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-fragment_3_0.xsd"
version="3.0"
id="myapp-frontendmodul">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
</web-fragment>
AktuelleSchritteAlle.xhtml (module 2):
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
>
<f:view locale="de">
<h:body>
<h:outputText>test</h:outputText>
</h:body>
</f:view>
</html>
Thank you in advance.
Related
I created a webapp using the maven archetype for Jersey 2.27 quick start, but IntelliJ IDEA show the following error:
Error:(7, 24) 'org.glassfish.jersey.servlet.ServletContainer' is not assignable to 'javax.servlet.Servlet'
This is the generated web.xml:
<web-app version="2.5" 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">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.myaddress</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
</web-app>
How can I fix this?
This is not a theory. I have proof. I've been on this problem for almost a day. My jsp seem to can't read/find CSS. I've done a lot of solutions but nothing work. Until I decide maybe one of my files is causing it. Then I do trial and error. Deleting file to see which one causes it.
Until i'm in web.xml. I deleted web.xml, run the JSP and boom it read the CSS. I copy back the web.xml and then again my css can't be read.
By the way i'm using spring mvc, and my project is maven web application.
below are my codes:
jsp(css link part):
<link rel="stylesheet" type="text/css" href="../../css/logincss.css">
web.xml:
<?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">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<servlet>
<servlet-name>DpServlet</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DpServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
I think the error is that when i'm requesting a css file, the request goes to dispatcherservlet so that is so error. How can I fix my problem? Please I need solution i've been on this problem for over a DAY! Thanks in advance.
I am working on a project and hit a brick wall. I couldn't find any resources or bug reports to solve this issue. I have a maven project setup as maven-archetype-webapp. I am new to JEE and it took me sometime to get this far but I have a better understanding of how some of this works. I have hit a brick wall and don't know how to solve the problem below.
I get the following warnings within the web.xml file
servlet-class references to non-existent class "servlets.RegisterServlet"
servlet-class references to non-existent class "servlets.HomePageServlet"
file name references to "index" that does not exist in web content
I get the following error in WildFly 10.x.
Caused by: java.lang.ClassNotFoundException: servlets.RegisterServlet from [Module "deployment.PracticeProject.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService.createServletConfig(UndertowDeploymentInfoService.java:723)
... 6 more
The java classes appear in the directory structure of the war so its packaging it correctly. For the entities, session beans and servlets I have a scope of provided for the dependencies of the pom.xml file.
My directory structure is as follows:
My web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>PracticeProject</display-name>
<servlet>
<servlet-name>RegisterServlet</servlet-name>
<servlet-class>servlets.RegisterServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegisterServlet</servlet-name>
<url-pattern>/register</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>HomePageServlet</servlet-name>
<servlet-class>servlets.HomePageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HomePageServlet</servlet-name>
<url-pattern></url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index</welcome-file>
</welcome-file-list>
</web-app>
edit:
CHKJ3013E: The URL Mapping "" is invalid. web.xml /PracticeProject/src/main/webapp/WEB-INF org.eclipse.jst.j2ee.webapplication.internal.impl.ServletMappingImpl#53667dce (urlPattern: , name: null) Validation Message
I have started learning servlet programming. I am using eclipse IDE. I have created a simple dynamic web project and have one html file and one servlet program in it(LoginForm.html & LoginServlet.java). I want to display the html page to the user at first .I have also set up the welcome-file-list tag in the web.xml but when I run the project it doesn't display that page. I also tried to enter the url in the browser manually but it's also not working.It is giving the error as '404-Page not found'. My web.xml file is
<?xml version="1.0" encoding="UTF-8"?>
<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="WebApp_ID" version="2.5">
<display-name>LoginApp</display-name>
<welcome-file-list>
<welcome-file>LoginForm.html</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>LoginServlet</display-name>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.myprograms.servlet.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/logapp</url-pattern>
</servlet-mapping>
</web-app>
The URL I am using is http://localhost:8001/LoginApp/LoginForm.html. Please suggest any solution.
Which is the best way to integrate existent spring-MVC-Project with flex. I'am using Spring-2.5 lib with annotations.
e.g my list controller:
package xxx.xxx.controller;
#Controller
public class ListController {
#Autowired
private ColorHome colorHome;
#RequestMapping("/admin/colors.do")
public ModelMap colorsHandler() {
Collection<Object> colors = this.colorHome
.findColors();
return new ModelMap(colors);
}
I have also a colors.jsp which displays the colors. Now I would like to integrate flex as an UI-Layer. I only need to integrate the Spring-View with shown RequestMappings above.
Go get BlazeDS. Install it using the WAR file.
You'll also need the flex jar from Spring.
In your web.xml file, add this:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/flexContext.xml
</param-value>
</context-param>
<servlet>
<servlet-name>flex</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>flex</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
Create a flex-servlet.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:flex="http://www.springframework.org/schema/flex"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
</beans>
Create a flexContext.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:flex="http://www.springframework.org/schema/flex"
...
">
<flex:message-broker />
<flex:remoting-destination destination-id="flexService" ref="beanFromApplicationContext" />
</beans>
This should be enough to get you the remoting endpoints.
In Flex, create a remoteObject and give it a destination of "flexService" or whatever you set the destination-id on the to.
Spring has a project for its integration with Flex,BlazeDS and Java.
This might help you. Spring n Flex integration