1、Maven Dependencies 与 Referenced Libraries有区别,程序中添加的第三方库文件.jar需要添加到Maven Dependencies对应的文件夹下面,也就是对应工程的\WEB-INF\lib路径下面,不然会出现错误ClassNotFoundException,添加方法是在pom.xml文件中添加dependency,dependency中的<groupId><artifactId><version>可以通过网址:http://mvnrepository.com/来查找,例如
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.1</version>
</dependency>
2、访问静态资源
- 首先需要在servlet-context.xml中进行配置
整个配置文件的代码如下:<resources mapping="/resources/**" location="/resources/" />
<?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --> <!-- Enables the Spring MVC @Controller programming model --> <annotation-driven /> <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --> <resources mapping="/resources/**" location="/resources/" /> <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --> <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <beans:property name="prefix" value="/WEB-INF/views/" /> <beans:property name="suffix" value=".jsp" /> </beans:bean> <context:component-scan base-package="com.ticket.controller" /> </beans:beans>
- 然后在对应的jsp中指定路径,此处我用的是绝对路径,相对路径的方法可在google中搜索jsp src找相关资料
<script type="text/javascript" src="<%=request.getContextPath()%>/resources/processing-1.4.1.js"> </script>
String city = "武汉";
String city_UTF8 = null;
/*如果url中含有中文参数,需要进行URLEncoding处理*/
try {
city_UTF8 = URLEncoder.encode(city,"UTF-8");
} catch (UnsupportedEncodingException e) {
System.out.println(city_UTF8);
}