您好,登錄后才能下訂單哦!
404這個錯誤真的是一言難盡!不過大多是配置文件出錯,認真修改還是可以的
1.web.xml配置錯誤:
默認首頁沒有寫的,在web.xml添加一個就行(前提是你有jsp頁面,名字不要寫錯):
比如這個:
<welcome-file-list> <welcome-file>Login.jsp</welcome-file> </welcome-file-list>
2.IDEA JavaWeb項目運行找不到對應Servlet映射的JSP頁面
在servlet3.0以后提供了注解配置,這樣就不需要在web.xml中配置。使用IDEA生成的servlet文件的注解配置如下(第一行):
@WebServlet(value = "/AdminServlet") public class AdminServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } }
對于怎樣配置請看:
路徑:File > Settings > Editor > File and Code Templates > Other > Web > Java code templates 下第二個點開右邊編輯模板
如下(這是我的模板):
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end #parse("File Header.java") @javax.servlet.annotation.WebServlet(value = "/${Entity_Name}") public class ${Class_Name} extends javax.servlet.http.HttpServlet { protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException { doPost(request,response); } protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException { } }
3.創建了一個和以前項目名稱相同的項目(項目名稱結構一樣),把以前的覆蓋了 然后運行就404了;
第一時間想到的就是配置文件有錯就開始找 :這個是我剛發現的解決辦法:
啟動運行后跳轉的頁面發現不是你定義的頁面報404錯誤,這就需要你在workspace.xml里面找了:
你的項目名 > .idea > workspace.xml,找到里面不是你首次跳轉的jsp的名字,修改為你定義的jsp名字
具體在這里:把名字修改一下就好了
<component name="RunManager"> <configuration name="tomcat" type="#com.intellij.j2ee.web.tomcat.TomcatRunConfigurationFactory" factoryName="Local" APPLICATION_SERVER_NAME="Tomcat 7.0.47" ALTERNATIVE_JRE_ENABLED="true" ALTERNATIVE_JRE_PATH="C:\Program Files\Java\jdk1.8.0_191\jre"> <option name="OPEN_IN_BROWSER_URL" value="http://localhost:8080/Login.jsp" /> <option name="UPDATING_POLICY" value="restart-server" /> <deployment> <artifact name="SuShe:war exploded"> <settings> <option name="CONTEXT_PATH" value="/" /> </settings> </artifact> </deployment> <server-settings> <option name="BASE_DIRECTORY_NAME" value="Login_jsp_SuShe" /> </server-settings> <predefined_log_file id="Tomcat" enabled="true" /> <predefined_log_file id="Tomcat Catalina" enabled="true" /> <predefined_log_file id="Tomcat Manager" enabled="false" /> <predefined_log_file id="Tomcat Host Manager" enabled="false" /> <predefined_log_file id="Tomcat Localhost Access" enabled="false" /> <RunnerSettings RunnerId="Debug"> <option name="DEBUG_PORT" value="61238" /> </RunnerSettings> <ConfigurationWrapper VM_VAR="JAVA_OPTS" RunnerId="Cover"> <option name="USE_ENV_VARIABLES" value="true" /> <STARTUP> <option name="USE_DEFAULT" value="true" /> <option name="SCRIPT" value="" /> <option name="VM_PARAMETERS" value="" /> <option name="PROGRAM_PARAMETERS" value="" /> </STARTUP> <SHUTDOWN> <option name="USE_DEFAULT" value="true" /> <option name="SCRIPT" value="" /> <option name="VM_PARAMETERS" value="" /> <option name="PROGRAM_PARAMETERS" value="" /> </SHUTDOWN> </ConfigurationWrapper> <ConfigurationWrapper VM_VAR="JAVA_OPTS" RunnerId="Debug"> <option name="USE_ENV_VARIABLES" value="true" /> <STARTUP> <option name="USE_DEFAULT" value="true" /> <option name="SCRIPT" value="" /> <option name="VM_PARAMETERS" value="" /> <option name="PROGRAM_PARAMETERS" value="" /> </STARTUP> <SHUTDOWN> <option name="USE_DEFAULT" value="true" /> <option name="SCRIPT" value="" /> <option name="VM_PARAMETERS" value="" /> <option name="PROGRAM_PARAMETERS" value="" /> </SHUTDOWN> </ConfigurationWrapper> <ConfigurationWrapper VM_VAR="JAVA_OPTS" RunnerId="Run"> <option name="USE_ENV_VARIABLES" value="true" /> <STARTUP> <option name="USE_DEFAULT" value="true" /> <option name="SCRIPT" value="" /> <option name="VM_PARAMETERS" value="" /> <option name="PROGRAM_PARAMETERS" value="" /> </STARTUP> <SHUTDOWN> <option name="USE_DEFAULT" value="true" /> <option name="SCRIPT" value="" /> <option name="VM_PARAMETERS" value="" /> <option name="PROGRAM_PARAMETERS" value="" /> </SHUTDOWN> </ConfigurationWrapper> <method v="2"> <option name="BuildArtifacts" enabled="true"> <artifact name="SuShe:war exploded" /> </option> </method> </configuration> </component>
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。