Home > front end >  The Servlet to jump to the JSP page in 404 how to solve
The Servlet to jump to the JSP page in 404 how to solve

Time:09-16

Recently in the front-end developer, redirect users to use sendRedirect always appear problem,
This is my folder structure:

Servletdemo1 code is as follows:
 
Package com. Wx. Servlet.

The import javax.mail. Servlet. ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
The import javax.mail. Servlet. HTTP. It;
The import javax.mail. Servlet. HTTP. HttpServletResponse;
import java.io.IOException;

@ WebServlet (name="Servletdemo1")
Public class Servletdemo1 extends the HttpServlet {
Protected void doPost (it request, HttpServletResponse response) throws ServletException, IOException {

}

Protected void doGet (it request, HttpServletResponse response) throws ServletException, IOException {
//to redirect
The response. SendRedirect ("./jspdemo1/not JSP ");
}
}

The JSP page code is as follows:
 
<% -- --
Created by IntelliJ IDEA.
User: W
Date: 2020/6/11
Time:
"To change this template use File | Settings | File Templates.
- % & gt;
<% @ page contentType="text/HTML. Charset=utf-8 "language=" Java "% & gt;


Jspdemo1 & lt;/title> <br/></head> <br/><body> <br/><Hl> After the jump page! </hl> <br/></body> <br/></html> <br/></pre> <br/>The web.xml file configuration is as follows: <br/><pre> <br/><? The XML version="1.0" encoding="utf-8"?> <br/><Web - app XMLNS="http://xmlns.jcp.org/xml/ns/javaee" <br/>XMLNS: xsi="http://www.w3.org/2001/XMLSchema-instance" <br/>Xsi: schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" <br/>Version="4.0" & gt; <br/><Servlet> <br/><servlet-name> Servlet1 & lt;/servlet - name> <br/><The servlet - class> Com. Wx. Servlet. Servletdemo1 & lt;/servlet - class> <br/></servlet> <br/><The servlet - mapping> <br/><servlet-name> Servlet1 & lt;/servlet - name> <br/><Url - pattern>/servletdemo1 & lt;/url - pattern> <br/></servlet - mapping> <br/></web - app> <br/></pre> <br/>Tomcat configuration is as follows: <br/><img SRC="https://img.codepudding.com/202009/77069161942132.png" Alt=""/> <br/><img SRC="https://img.codepudding.com/202009/77069161942133.png" Alt=""/> <br/>Run the server: <br/><img SRC="https://img.codepudding.com/202009/77069161942134.png" Alt=""/> <br/>After input address servletdemo1, page jump, 404 <br/><img SRC="https://img.codepudding.com/202009/77069161942135.png" Alt=""/> <br/>Is there a bosses know how to return a responsibility? Ask for help<p class="article - content rp"> CodePudding user response: </p>Don't sink!!!<p class="article - content rp"> CodePudding user response: </p>First you need to confirm your project on tomcat webapps is scattered, for example: demo. Which yao for access to your address: http://x/demo/your JSP and servlet mapping <br/><br/><br/>If the ROOT: http://x/your JSP and servlet mapping<p class="article - content rp"> CodePudding user response: </p>As for JSP how to write the address: the safest and most worry is to use c: url, <br/><br/><pre> <br/><C: url var="post_url" value="https://bbs.csdn.net/user/add"/& gt; <br/><The form method="post" action="${post_url}" & gt; <br/></forum> <br/></pre> <br/><br/>Whether it is a demo or ROOT, you only need to write the mapping address <br/><br/><p class="article - content rp"> CodePudding user response: </p><img SRC="https://img.codepudding.com/202009/77069161942136.png" Alt=""/> </div> <div class="th_page th_page_color"></div> <div class="umCopyright"> <p>Page link:<a href="/frontend/4243.html" target="_blank" style="color:#999">https//www.codepudding.com/frontend/4243.html</a></p> </div> <div class="detail-arr"> <div class="detail-arr-left">Prev:<a href='/frontend/4242.html'>Super star learn the teacher set the examination, how to view the paper in advance?</a></div> <div class="detail-arr-right">Next:<a href='/frontend/4244.html'>How to write the beginners, bosses solutions, learn from the answer</a></div> </div> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="hot-tags neitags"> <ul> <li><i class="iconfont icon-x-tags"></i> Tags:  </li> <a href='/e/tags/?tagname=other' target='_blank'>other</a> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="xiangguan"> <ul class="msg msghead"> <li class="tbname">Related</li> </ul> <ul> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="flinks"> <ul> <li><i class="iconfont icon-x-tags"></i> Links:  </li> <li class="liflinks"><a target="_blank" href="/" title="CodePudding">CodePudding</a></li> </ul> </div> </div> </div> </div> <div class="footer"> <p><span style="font-size:16px;color:#666;font-weight: bold">About Us:</span>  <a href="https://www.codepudding.com/contact.html">Contact Us</a>      <a href="https://www.codepudding.com/service.html">Terms of Service</a>      <a href="https://www.codepudding.com/privacy.html"> Privacy Policy</a></p> <p class="foot_info">Copyright © 2010-2023,Powered By <a href="/" target="_blank">CodePudding</a> </p> </div> <script type="text/javascript" src="/skin/code/tianhu.js"></script> </body></html>