在项目中,有需求做一个问卷调查,需要通过发送给用户的邮件链接中,直接进入问卷页面。但是,每个请求的url都要通过过滤器,所以,可以再主页面的controller层进行判断:
<servlet>
<servlet-name>sun</servlet-name>
<servlet-class>com.sunivo.web.base.servlet.sunDispatcherServlet</servlet-class>
<init-param>
<param-name>namespace</param-name>
<param-value>classes/sun-servlet</param-value>
</init-param>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sun</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
上面的是对应web.xml的配置,sunivoDispatcherServlet是自定义的,继承自DispatcherServlet,通过对应的doService方法,然后会到达对应的IndexController中的
*/
@SuppressWarnings("all")
@RequestMapping(value = "/", method = { RequestMethod.GET })
public String index(HttpServletResponse response, HttpServletRequest request,Model model) throws Exception {
String loginType=request.getParameter("loginType");
model.addAttribute("loginType", loginType);
String questionId = decoderByBase64(request.getParameter("questionId"));
if(questionId != null && StringUtils.isNotEmpty(questionId)){
这个方法,因为他的requestMapping为“/”,所以我们只要发给用户的邮箱用主页url,在加对应参数,判断是否是问卷页面的url,如果是,直接走问卷的controller,否则,按原流程走
例如:http://127.0.0.1:8080/sunivoOA-web/?questionId=1 对应http://127.0.0.1:8080/sunivoOA-web/为访问系统的url,questionId可以作为去问卷页面的参数,通过questionId的判断,可以调到对应controller,不需要通过登录,直接就会跳到问卷页面。