1 在WEB.XML中配置Spring MVC的前端控制器(DispatcherServlet).
<servlet> <servlet-name> example </servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup> 1 </load-on-startup> </servlet> <servlet-mapping> <servlet-name> example </servlet-name> <url-pattern> /example/* </url-pattern> </servlet-mapping>
2 在 /WEB-INF/目录下新建一个example-servlet.xml.
2.1 解析例如从HTML表单支持处理文件上传多部分请求
<bean id="multipartResolver" class="org.springframework.web.multipart.support.StandardServletMultipartResolver"></bean>
2.2 example-servlet.xml中添加视图解析器
<mvc:annotation-driven /> <!-- 开启注解扫描 --> <context:component-scan base-package="com.bird.lend.lshop.**.action" /> <!-- 视图解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/pages/"></property> <property name="suffix" value=".jsp"></property> </bean>
3 拦截器需实现HandlerInterceptor类.
登录拦截器
public class LoginInterceptor implements HandlerInterceptor
时间: 2024-11-10 21:57:47