您好,登錄后才能下訂單哦!
404這個(gè)錯(cuò)誤真的是一言難盡!不過(guò)大多是配置文件出錯(cuò),認(rèn)真修改還是可以的
1.web.xml配置錯(cuò)誤:
默認(rèn)首頁(yè)沒(méi)有寫(xiě)的,在web.xml添加一個(gè)就行(前提是你有jsp頁(yè)面,名字不要寫(xiě)錯(cuò)):
比如這個(gè):
<welcome-file-list> <welcome-file>Login.jsp</welcome-file> </welcome-file-list>
2.IDEA JavaWeb項(xiàng)目運(yùn)行找不到對(duì)應(yīng)Servlet映射的JSP頁(yè)面
在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 { } }
對(duì)于怎樣配置請(qǐng)看:
路徑:File > Settings > Editor > File and Code Templates > Other > Web > Java code templates 下第二個(gè)點(diǎn)開(kāi)右邊編輯模板
如下(這是我的模板):
#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.創(chuàng)建了一個(gè)和以前項(xiàng)目名稱(chēng)相同的項(xiàng)目(項(xiàng)目名稱(chēng)結(jié)構(gòu)一樣),把以前的覆蓋了 然后運(yùn)行就404了;
第一時(shí)間想到的就是配置文件有錯(cuò)就開(kāi)始找 :這個(gè)是我剛發(fā)現(xiàn)的解決辦法:
啟動(dòng)運(yùn)行后跳轉(zhuǎn)的頁(yè)面發(fā)現(xiàn)不是你定義的頁(yè)面報(bào)404錯(cuò)誤,這就需要你在workspace.xml里面找了:
你的項(xiàng)目名 > .idea > workspace.xml,找到里面不是你首次跳轉(zhuǎn)的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>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。