学习Spring Framework中遇到的各种问题

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>

3、用HttpClient执行Get请求时,如果url中含有中文,需要进行URLEncoding处理,例如:
String city = "武汉";
        String city_UTF8 = null;

        /*如果url中含有中文参数,需要进行URLEncoding处理*/
        try {
            city_UTF8 = URLEncoder.encode(city,"UTF-8");
        } catch (UnsupportedEncodingException e) {
            System.out.println(city_UTF8);
        }


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值