IDEAJavaWeb项⽬启动运⾏后出现404错误的解决⽅法
404这个错误真的是⼀⾔难尽!不过⼤多是配置⽂件出错,认真修改还是可以的
l配置错误:
默认⾸页没有写的,在l添加⼀个就⾏(前提是你有jsp页⾯,名字不要写错):
⽐如这个:
<welcome-file-list>
<welcome-file>Login.jsp</welcome-file>
</welcome-file-list>
2.IDEA JavaWeb项⽬运⾏不到对应Servlet映射的JSP页⾯
在servlet3.0以后提供了注解配置,这样就不需要在l中配置。使⽤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错误,这就需要你在l⾥⾯了:
你的项⽬名 > .idea > l,到⾥⾯不是你⾸次跳转的jsp的名字,修改为你定义的jsp名字
具体在这⾥:把名字修改⼀下就好了
<component name="RunManager">
<configuration name="tomcat" type="#com.intellij.at.TomcatRunConfigurationFactory" factoryName="Local" APPLICATION_SERVER_NAME="Tomcat 7.0.47" ALTERNATIVE_JRE_ENABLED="true" ALTERNATIVE_JRE_PATH="C:\Program F  <option name="OPEN_IN_BROWSER_URL" value="localhost:8080/Login.jsp" />
<option name="UPDATING_POLICY" value="restart-server" />
<deployment>
<artifact name="SuShe:war exploded">jsp源码下载脚本之家
<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">thread类的作用
<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="" />
thread gauge什么意思
<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" />
sql2008教程视频<STARTUP>
<option name="USE_DEFAULT" value="true" />
<option name="SCRIPT" value="" />
<option name="VM_PARAMETERS" value="" />
<option name="PROGRAM_PARAMETERS" value="" />
</STARTUP>
idea配置artifacts
<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="" />
page对象有什么作用
</SHUTDOWN>
</ConfigurationWrapper>
<method v="2">
<option name="BuildArtifacts" enabled="true">
<artifact name="SuShe:war exploded" />
</option>
</method>
</configuration>
</component>
以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。