Simple Example of SpringMVC static file (image) Access + js access

Source: Internet
Author: User
Project File layout: web. xml file: & lt ;? Xmlversion & quot; 1.0 & quot; encoding & quot; UTF-8 & quot ;? & Gt; & lt; web-appversion & quot; 2.5 & quot; xmlns & quot; http://java.sun.com/xml/ns/javaee"

Project File layout:

 

 

Web. xml file:


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>

Index. jsp


SpringMVC
Org. springframework. web. servlet. DispatcherServlet

ContextConfigLocation
Classpath *: config/spring-servlet.xml

1


SpringMVC
/


Spring-servlet.xml files:


Xmlns = "http://www.springframework.org/schema/beans"
Xmlns: context = "http://www.springframework.org/schema/context"
Xmlns: p = "http://www.springframework.org/schema/p"
Xmlns: mvc = "http://www.springframework.org/schema/mvc"
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-3.0.xsd
Http://www.springframework.org/schema/context
Http://www.springframework.org/schema/context/spring-context-3.0.xsd
Http://www.springframework.org/schema/mvc
Http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
">










 
 


 
 

StaticController. java file:

Package com. mcm. web. controller;

Import javax. servlet. http. HttpServletRequest;
Import javax. servlet. http. HttpServletResponse;

Import org. springframework. web. servlet. ModelAndView;
Import org. springframework. web. servlet. mvc. multiaction. MultiActionController;

Public class StaticController extends MultiActionController {
Public ModelAndView img (HttpServletRequest request, HttpServletResponse response ){
Return new ModelAndView ("/aaa ");
}
}

Aaa. jsp file:

<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %>
<% @ Taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<%
String path = request. getContextPath ();
String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/";
%>






My JSP 'aaa. jsp 'starting page

 
 
 
 
 
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.