JSP not found when running Spring Boot in IDE, but works when running manually - spring

I have a java web application code (checked out from remote git server - others users dont have my problem) and imported it into IntelliJ (newest edition), I performed from IDE following steps: maven clean install, run (its spring boot application so there are no arguments or parameters to configure in run configuration to set - I compared it with settings from IDE on ohter computer - no differences) and then I sent a request to server with resul "404 - /WEB-INF/../some.jsp not found) but in unzipped WAR this file exists ! Moreover, when I run this war manually (java -jar app.war) my request was sent successfully with positive result - view was displayed. So, there is definitelly sth wrong with IDE. I tried almost everything: i reinstalled IDE, I deleted .m2 repository, I checked out code again, I tried with different IDE version but problem still arrives. What may be wrong ?

maybe your application use dispatcher servlet ,so your request mapped and you cannot request to exact path of jsp file and your browser show 404 not found
,check your web.xml that has like this code
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
and search *.xml file that use jspResolver or somthing like this
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
if you find it, you should request for example like this
http://localhost:8080/nameofyourapp/index
instead of http://localhost:8080/nameofyourapp/WEB-INF/view/index.jsp

Spring Boot does not include Jasper by default and therefore JSP rendering doesn't work unless you explicitly include the library:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
The below libs are also necessary, hope you have already added:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper-el</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jsp-api</artifactId>
<version>${tomcat.version}</version>
</dependency>

Related

spring boot mvc downloding file instead of resolving jsp

I have written a simple spring boot mvc application with jsp as view resolver.
Cofiguration inside application.properties
spring.mvc.view.prefix=/view/
spring.mvc.view.suffix=.jsp
There is a jsp file with the name returned from the Controller
Inside pom.xml
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-el</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
However, when I hit the controller, instead of displaying the jsp page, its getting downloaded as file. If I configure the internal resolver to .html, its working. But when I try to use the jsp extension, it's not working.
Spring Boot does a lot of magic out of box. But in situations like these, How to know the list of jars registered in the container? Please let me know where I am going wrong.

Why is the JSP page not rendered while deploying a SpringBoot App in Pivotal Web Services while it works fine with Thymeleaf and other views

The application is deployed in pivotal web services and when I hit the application with the link https://webstore.cfapps.io/, the login.jsp page is not rendered.
The same application runs successfully in the local server. I tried for searching the same issue but none of them solve the problem. I used both STS deployment and also tried cf command line for deploying separately but couldn't get the result.
I am giving you the details.
The error shown.
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sat Jan 14 04:21:40 UTC 2017
There was an unexpected error (type=Not Found, status=404).
/WEB-INF/jsp/login.jsp
My pom file is
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
ecommerce.com
webstore
0.0.1-SNAPSHOT
jar
ecommerce-webstore
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
1.4.2.RELEASE
UTF-8
UTF-8
1.8
org.springframework.boot</groupId> spring-boot-starter-security</artifactId>
</dependency> -->
org.springframework.boot
spring-boot-starter-web
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
org.springframework.boot
spring-boot-maven-plugin
3.MY application.properties file is
spring.mvc.view.prefix:/WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
spring.datasource.url= jdbc:mysql://localhost:3306/ecommercestore
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update
3.The manifest.yml generated after deployment is
applications:
name: webstore
memory: 1024M
host: webstore
domain: cfapps.io
buildpack: standard buildpack provided in git hub. I am not writing link
services:
cleardb
The result after giving the following command from cmd is
cf push webstore -p target/webstore-0.0.1-SNAPSHOT.jar --no-start
......................................................................
C:\Users\santosh dahal\Desktop\excellerant\ecommerce-webstore>cf push webstore -p target/webstore-0.0.1-SNAPSHOT.jar --no-start
Creating app webstore in org santosh-org / space Myspace as santoshdahal2072#gmail.com...
OK
Using route webstore.cfapps.io
Binding webstore.cfapps.io to webstore...
OK
Uploading webstore...
Uploading app files from: C:\Users\SANTOS~1\AppData\Local\Temp\unzipped-app904639435
Uploading 478.9K, 140 files
Done uploading
OK
6. I went to myapp in pivotal and started the application after binding the database cleardb to the same instant and application, the application runs successfully with the Running Status
7. the folder arrangement is as follows:
I have kept jsp pages in
src/main/webapp/WEB-INF/jsp/login.jsp
While the application.properties is in src/main/resources.
I will provide more details if needed. the github link for the code is
here
you are packaging it as a jar not as a war . In that case put your jsp files into static folder under resources or follow the below the link to understand better on the packaging aspect. But I feel it is better to package it as a war
Package a spring boot application including JSPs and static resources.
Also please check the jar generated before pushing the app to PWS whether jsp is avaibale at the requested path.

OrientDB with spring mvc configuration

Please suggest me how can i configure the orientdb with spring mvc.
<bean id="databaseFactory" class="org.ops4j.orient.spring.tx.OrientObjectDatabaseFactory"
p:url="remote:localhost/MyDB" p:username="userName" p:password="pwd" />
<bean id="orTransactionManager" class="org.ops4j.orient.spring.tx.OrientTransactionManager"
p:databaseManager-ref="databaseFactory" />
I have added above code into my mvc-dispacher-servlet.xml file
and i have added dependencies also in to pom.xml
<dependency>
<groupId>org.ops4j.orient</groupId>
<artifactId>orient-spring-tx</artifactId>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-core</artifactId>
<version>2.2.13</version>
</dependency>
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-graphdb</artifactId>
<version>2.2.13</version>
</dependency>
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-enterprise</artifactId>
<version>2.2.0-beta</version>
</dependency>
My OrientDb server is 2.2.13 version which is latest.
help me in configuring it.if possible suggest a sample project URL also.
Thank You

JSP with JSTL not working on tomcat 8 in a Spring Boot Application

I have include these dependency in pom.xml.
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
Still i am getting javax.servlet.ServletException: java.lang.NoSuchMethodError: org.apache.el.lang.ELSupport.coerceToType(Ljavax/el/ELContext;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
I also included one more dependency in pom.xml.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
Then the error changed to An exception occurred processing JSP page /WEB-INF/views/index.jsp at line 7 4: <%# page session="false" %> [[[[ JSTL CODE USING EXPRESSION LANGUAGE]]]
Everything is working fine in eclipse ide but not working on deploying on separate tomcat server.
You are getting below error because of the presence of tomcat-embed-el-8.0.32.jar in your Tomcat 8.0\webapps\AppName\WEB-INF\lib folder.
javax.servlet.ServletException: java.lang.NoSuchMethodError:
org.apache.el.lang.ELSupport.coerceToType(Ljavax/el/ELContext;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
This error is due to the conflict between the ELSupport.class provided by Tomcat and tomcat-embed-el-8.0.32.jar present in the applications lib directory, hence you get that error in Tomcat. And it works fine in Eclipse since it uses embedded server.
To fix this issue add below code in your pom.xml:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-el</artifactId>
<scope>provided</scope>
</dependency>
When you add tomcat-embed-el dependency as scope=required then the tomcat-embed-el-8.0.32.jar will not be added into your \AppName\WEB-INF\lib folder.
For information check this Issue on Spring-Boot's Github repository.
Also you can use these sample apps:
Spring-Boot-Jsp-Demo configured with InternalResourceViewResolver bean.
spring-boot-sample-tomcat-jsp configured with application.properties just like in the spring-boot sample apps.

Can not find the tag library descriptor for "http://tiles.apache.org/tags-tiles"

I am creating an application using Tiles, Spring and Hibernate.
When when running, it is showing following error:
Can not find the tag library descriptor for "http://tiles.apache.org/tags-tiles"
All the jars are included and mapping is also seeing fine. Where I am going wrong?
The url looks ok.
Your problem sounds a bit like you are missing some tiles jars. Make sure that a jar containing tiles-jsp.tld is added to your projects web libs folder.
One jar that contains this file is for example: tiles-jsp-2.2.1.jar.
In pom.xml file appended below artifacts and compiled well this time.
<!-- Tiles -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-api</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
<version>2.1.2</version>
</dependency>
I copied the whole file with the taglib declaration from somewhere else and got the same compilation error. I deleted the file, created a new one and pasted the same contents. Sounds weird but worked! Hope it helps someone. :)
I had this problem even after having tiles-jsp.2.0.6.jar. So i found the solution by removing the jar manually from the maven dependencies and adding it as an external jar.. It worked, you may also try so..
Adding the tiles dependency in pom.xml of Spring project will help-
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>3.0.7</version>
</dependency>

Resources