Skip to content Skip to sidebar Skip to footer

Jsp Web Content Folder Uploaded Image Some Not Showing Up Get 404 Errot

Spring MVC tutorial - Crunchify Tutorial

Model-View-Controller (MVC) architecture provides the simplest mode to develop flexible and loosely coupled web applications.

In this tutorial we will go over on how to create your 1st Jump MVC application with very detailed steps.

Do you lot accept whatsoever of below questions?

  • Fundamentals of Spring MVC 5.two.iii
  • Developing a Spring Framework MVC v application step-past-step..
  • coffee – Spring MVC tutorial from the scratch
  • Jump MVC Fast Tutorial
  • Spring MVC Framework Tutorial
  • Kickoff Spring MVC application tutorial
  • Spring 5.ten MVC Tutorials, AJAX Demo, jQuery Demo, JavaScript Demo, Tips & Tricks Spring 5 MVC

Then you lot are at correct place. Here I'll demonstrate simpleSpring MVC framework for edifice web applications.

First matter starting time – Let's Setup Environment

Tutorial final updated and verified: September 2020 with below Tool versions.

I'm using below tools which you may need to download if you don't have already.

  1. Tomcat ix.0.38 – Download latest Apache Tomcat from this link.
  2. Brand certain you download Eclipse IDE forJava EE Developers (2020‑09 R) – Download link. (diagram below)
  3. Spring 5.2.9.RELEASE (No download required) – we will apply Maven dependency.
  4. JDK xv – Download link.
Simplest Spring MVC tutorial by Crunchify.com

Make sure you lot download latest Java EE Developer Kit:

Eclipse Photon IDE 4.8.0

Principal Goal

Main goal for this tutorial to create Spring MVC Application in the simplest fashion.


Before we get started let'south run across what we will see at the cease of this tutorial 🙂

This is how our application result volition look like. This is a final outcome once you complete all below steps.

Here is a final result: Welcome page ==> alphabetize.jsp

CrunchifySpringMVCTutorial index.jsp page

Result returns from Controller Class 🙂

Message Coming from Controller

Now Let'south get started on Tutorial

Footstep-1

  • Open Eclipse
  • Create New Eclipse Workspace – This is must to avoid any existing workspace config issue.
Create New Eclipse Workspace - Crunchify Tips

Step-ii

  • Click on File
  • Click on New
  • Cull Dynamic Web Project
  • One popup window, Provide Project Name: CrunchifySpringMVCTutorial
  • Make sure you utilise Target Runtime as Apache Tomcat ix.0
    • If you don't see Target Runtime and then follow these steps
  • Choose Configuration as Default Configuration
Create Crunchify Spring MVC Dynamic Web Project

Step-3

Catechumen Projection to Maven Project to add all required Spring MVC dependencies to project.

Steps:

  • Right click on project
  • Configure
  • Catechumen to Maven projection
Convert Dynamic Web Project to Maven Project
Convert CrunchifySpringMVCTutorial to Maven project

Footstep-iv

Open pom.xml file and add below jar dependencies to project.

Crunchify Spring MVC pom.xml Dependencies

NOTE: Here is my pom.xml file. Make sure you lot update Java version to 13 if you lot oasis't yet moved to JDK xiii. We will keep updating this tutorial to latest Spring MVC version.

So below pom.xml file may have different (latest) version of Jump MVC dependencies than above image 🙂

Step-5

Create new Leap Configuration Bean file:/WebContent/Spider web-INF/crunchify-servlet.xml

Create crunchify-servlet.xml file - Spring MVC project

crunchify-servlet.xml

In the above crunchify-servlet.xmlconfiguration file, we have defined a tag <context:component-scan> . This volition allow Leap to load all the components from packagecom.crunchify.controller  and all its child packages.

This will load our CrunchifyHelloWorld.form . Also we have defined a bean viewResolver. This bean will resolve the view and add prefix string /WEB-INF/jsp/  and suffix .jsp to the view in ModelAndView.

Note that in our CrunchifyHelloWorld class, we have return a ModelAndView object with view name welcome.

This will be resolved to path /Web-INF/jsp/welcome.jsp .

Step-6

Create new file web.xml if it'south already non there.  Map Jump MVC in/WebContent/Spider web-INF/web.xml file.

NOTE: if yous don't see web.xml file in your "dynamic web projection" then follow these steps.

web.xml

The above code in spider web.xml will map DispatcherServlet with url pattern /welcome.jsp. Besides note that we accept define index.jsp as welcome file.

Ane affair to annotation here is the name of servlet in <servlet-proper name> tag in web.xml. One time the DispatcherServlet is initialized, it will looks for a file name [servlet-name]-servlet.xml  in WEB-INF folder of web application. In this example, the framework volition look for file called crunchify-servlet.xml.

Pace-7

Create Controller Class.

  • Right click on Java Resources -> src
  • Click New -> Course
  • Package: com.crunchify.controller
  • Filename: CrunchifyHelloWorld.coffee
Create Spring Controller Class CrunchifyHelloWorld

CrunchifyHelloWorld.java

Note that nosotros accept annotated the CrunchifyHelloWorld class with @Controller and @RequestMapping("/welcome"). When Spring scans our parcel, information technology will recognize this edible bean equally being a Controller bean for processing requests. The @RequestMapping notation tells Jump that this Controller should procedure all requests get-go with /welcome in the URL path. That includes /welcome/* and /welcome.html.

The helloWorld() method returns ModelAndView object. The ModelAndView object tries to resolve to a view named "welcome" and the data model is beingness passed back to the browser so we can access the data within the JSP. The logical view proper noun will resolve to /WEB-INF/jsp/welcome.jsp . Logical name "welcome" which is return in ModelAndView object is mapped to path /WEB-INF/jsp/welcome.jsp.

The ModelAndView object likewise contains a message with fundamental "message" and Detailed value. This is the data that we are passing to our view. Unremarkably this will exist a value object in grade of java bean that will incorporate the data to exist displayed on our view. Here we are simply passing a cord.

Step-8

The View –Create new file/WebContent/index.jsp.

index.jsp

Create some other file/WebContent/WEB-INF/jsp/welcome.jsp.

NOTE: Don't forget to create jsp folder and put welcome.jsp inside that 🙂

welcome.jsp

After everything this is how your workspace should look similar.

Simplest Spring MVC Tutorial Project Structure - Crunchify

Step-9

Right Click on Project -> Run As -> Maven Build...

Maven Run-as - Maven Build in Eclipse IDE

Add Goals: clean install. Click Apply and Run.

Clean Install maven Spring project

Yous should see build success message:

Spring MVC Maven Clean Install Build Success Message

Where are all of my .jar files?

You volition run across all .jar files nether /target folder. Screenshot.

Footstep-10

  • If you don't encounter Tomcat Server in Servers tab then follow steps to add Apache Tomcat to Eclipse.
  • Deploy project to Apache Tomcat
    • Correct click
    • Add and Remove
    • Add Project to server (correct side section).
  • Click on Start.
Start Apache Tomcat in Eclipse - Crunchify Tips

Make sure you come across below logs. That means your awarding is successfully deployed on Tomcat Web Server.

Step-11. Done.

Visit: http://localhost:8080/CrunchifySpringMVCTutorial/ and you should be all gear up.

Hurray.. At present y'all know Hi Earth Bound MVC v Example. Allow me know if you come across any exception while running this. There are lot more than example you tin can find here.

Practice you desire to include JS, CSS and images into JSP file? Follow this tutorial: Best way to Add together/Integrate JS, CSS and images into JSP file using 'mvc:resources mapping'.


Having trouble? Any issue?

Triaging Pace-ane – Having HTTP Status 404 fault?

Make sure welcome.jsp file is inside jsp folder
Likewise, follow below tutorial:

Triaging pace-2 – URL doesn't work? Tomcat mistake?

Make sure you lot add together Apache Tomcat Server to Targeted Runtime. Which you may accept selected in Pace-1. Tomcat 7 or 8 any – server should piece of work.

Spring MVC tutorial - Eclipse Target Runtime Setting

Triaging Step-3 – maven errors?

Brand sure to update all maven dependencies.

Force Update dependencies - Spring MVC tutorial

Experience free to e-mail or comment below if you have any problem running above tutorial.

Share:

canoseemusting.blogspot.com

Source: https://crunchify.com/simplest-spring-mvc-hello-world-example-tutorial-spring-model-view-controller-tips/

Post a Comment for "Jsp Web Content Folder Uploaded Image Some Not Showing Up Get 404 Errot"