我有一个登录页面,我想重定向到注册页面。但是我明白了
HTTP Status 404 - /registration.jsp
错误。路径或项目层次结构:snapshot
我想要的是,如果用户没有被拒绝,他们可以通过点击
来注册
我做得不对
main.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().append("Served at: ").append(request.getContextPath());
RequestDispatcher view = request.getRequestDispatcher("/WEB-INF/Views/System/index.jsp");
view.forward(request, response);
String action = request.getParameter("action");
if(action.equals("register"))
{
view = request.getRequestDispatcher("/WEB-INF/Views/System/registration.jsp");
view.forward(request, response);
}
}
的index.jsp
<legend> Login to Jupiter </legend>
<table class="table" border="1" width="30%" cellpadding="3">
<thead>
<tr>
<th colspan="2">Login Here</th>
</tr>
</thead>
<tbody>
<tr>
<td>User Name</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="userpass" /></td>
</tr>
<tr>
<td colspan="2">New Employee!! <a class="btn btn-info" href="/registration.jsp?action=register">Register Here</a></td>
</tr>
</tbody>
</table>
<input type="submit" name="action" value="Login" />
</fieldset>
</center>
</form>
</body>
</html>
错误日志
Feb 13, 2016 4:40:33 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [com.greensun.jupiter.controller.main] in context with path [/Jupiter] threw exception
java.lang.NullPointerException
at com.greensun.jupiter.controller.main.doGet(main.java:32)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
答案 0 :(得分:1)
您构造了重定向到不存在的JSP页面的URL,但您应该使用映射到充当控制器的servlet的URL。
<servlet-mapping>
<servlet-name>MainServlet</servlet-name>
<url-pattern>/main</url-pattern>
</servlet-mapping>
现在你应该创建一个链接
<a class="btn btn-info" href="${pageContext.request.contextPath}/main?action=register">Register Here</a>
在控制器中,您获得了register
操作的参数,并使用调度程序转发到registration.jsp
。
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String action = request.getParameter("action");
if(action != null && action.equals("register")) {
RequestDispatcher view = request.getRequestDispatcher("/WEB-INF/Views/System/registration.jsp");
view.forward(request, response);
} else {
PrintWriter out = response.getWriter();
out.print("Served at: "+request.getContextPath());
RequestDispatcher view = request.getRequestDispatcher("/WEB-INF/Views/System/index.jsp");
view.forward(request, response);
}
}