我設計了3個jsp頁面。基於url參數的重定向/轉發
index.jsp,login.jsp和newUser。 JSP
的index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Ho there!</title>
</head>
<body>
This is authorization page.
<br>
<a href="/AgileScrumBoard/index.jsp?action=new">Create a new account</a>
<br>
<a href="/AgileScrumBoard/index.jsp?action=login">Login with the existing</a>
</body>
</html>
NEWUSER和登錄都只是普通的香草jsp頁面。
這裏的servlet方法的doGet:
String action=request.getParameter("action");
if(action.equals("new")){
response.sendRedirect("/newUser.jsp");
}else if(action.equals("login")){
request.getRequestDispatcher("/login.jsp").forward(request, response);
}else{
request.getRequestDispatcher("/login.jsp").forward(request, response);
}
}
的問題是:爲什麼當我按下請求調度員沒有按鏈接;噸轉發我/我重定向到指定的jsp頁面?
PS:web.xml中
<servlet>
<servlet-name>Index</servlet-name>
<jsp-file>/index.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>Index</servlet-name>
<url-pattern>/index.jsp</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>MainController</servlet-name>
<servlet-class>controller.MainController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MainController</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
當我在Tomcat的運行我的應用程序:
請求是否在點擊瀏覽器中的鏈接後到達您的'doGet'方法? – hagrawal
是的,請求達到doGet方法。 –
您可以分享您訪問您的index.jsp的URL嗎? – hagrawal