我面临一个问题,尽管我正确输入了一个可以由控制器处理的有效url
地址,但它不会从控制器重定向到jsp(HTTP 404)。这是我的web.xml
,控制器和调试器显示给我的内容
我进入http://localhost:8080/AccessControl/produits.aspx
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>ApplicationAccessControl</display-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-beans.xml</param-value>
</context-param>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/application-servlet-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.aspx</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>default.aspx</welcome-file>
</welcome-file-list>
</web-app>
AgentAdministrativeController.java在控制器包中
package controller;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import dao.AgentAdministrative;
import services.AgentAdministrativeMetier;
import services.SessionBean;
public class AgentAdministrativeController {
@Autowired
AgentAdministrativeMetier services;
@Autowired
private SessionBean sessionBean;
@RequestMapping(value={"/connnexiontrait","/default"})
public String verifier(Model model,@RequestParam String username,@RequestParam String motdepasse,@RequestParam int labo){
Long t;
String arg1;
t=services.verifaccess(username, motdepasse, labo);
if (t.intValue()==0)
{
arg1="Nom d'utilisateur ou mot de passe ou numero de laboratoire sont incorrectes ,veuillez les ressaisir " ;
model.addAttribute("erreurs", arg1);
System.out.println("succes");
return "connexion";
}
else
{
System.out.println("succes");
return "produits";
}
}
@RequestMapping(value={"/produits"})
public String verifie(Model model)
{
return "produits";
}
}
这就是调试器向我展示的内容。
mars 29, 2015 8:32:12 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
AVERTISSEMENT: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:AccessControl' did not find a matching property.
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Server version: Apache Tomcat/8.0.20
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Server built: Feb 15 2015 18:10:42 UTC
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Server number: 8.0.20.0
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: OS Name: Linux
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: OS Version: 3.16.0-23-generic
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Architecture: i386
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Java Home: /usr/lib/jvm/java-7-openjdk-i386/jre
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: JVM Version: 1.7.0_75-b13
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: JVM Vendor: Oracle Corporation
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: CATALINA_BASE: /home/sami/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: CATALINA_HOME: /home/sami/Téléchargements/apache-tomcat-8.0.20
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Command line argument: -Dcatalina.base=/home/sami/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Command line argument: -Dcatalina.home=/home/sami/Téléchargements/apache-tomcat-8.0.20
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Command line argument: -Dwtp.deploy=/home/sami/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Command line argument: -Djava.endorsed.dirs=/home/sami/Téléchargements/apache-tomcat-8.0.20/endorsed
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Command line argument: -Dfile.encoding=UTF-8
mars 29, 2015 8:32:12 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFOS: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/server:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386:/usr/lib/jvm/java-7-openjdk-i386/jre/../lib/i386:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/client:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386::/usr/java/packages/lib/i386:/usr/lib/i386-linux-gnu/jni:/lib/i386-linux-gnu:/usr/lib/i386-linux-gnu:/usr/lib/jni:/lib:/usr/lib
mars 29, 2015 8:32:12 AM org.apache.coyote.AbstractProtocol init
INFOS: Initializing ProtocolHandler ["http-nio-8080"]
mars 29, 2015 8:32:12 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFOS: Using a shared selector for servlet write/read
mars 29, 2015 8:32:12 AM org.apache.coyote.AbstractProtocol init
INFOS: Initializing ProtocolHandler ["ajp-nio-8009"]
mars 29, 2015 8:32:12 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFOS: Using a shared selector for servlet write/read
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.Catalina load
INFOS: Initialization processed in 885 ms
mars 29, 2015 8:32:12 AM org.apache.catalina.core.StandardService startInternal
INFOS: Démarrage du service Catalina
mars 29, 2015 8:32:12 AM org.apache.catalina.core.StandardEngine startInternal
INFOS: Starting Servlet Engine: Apache Tomcat/8.0.20
mars 29, 2015 8:32:14 AM org.apache.catalina.core.ApplicationContext log
INFOS: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
hibernate framework !!
mars 29, 2015 8:32:15 AM org.apache.coyote.AbstractProtocol start
INFOS: Starting ProtocolHandler ["http-nio-8080"]
mars 29, 2015 8:32:15 AM org.apache.coyote.AbstractProtocol start
INFOS: Starting ProtocolHandler ["ajp-nio-8009"]
mars 29, 2015 8:32:15 AM org.apache.catalina.startup.Catalina start
INFOS: Server startup in 2937 ms
mars 29, 2015 8:32:58 AM org.apache.catalina.core.ApplicationContext log
INFOS: Initializing Spring FrameworkServlet 'action'
这是application-servlet-config.xml
文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:sec="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-2.0.xsd">
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/Pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
您的控制器有几个问题。
-
您的控制器缺少
@Controller
注释。 -
您的application-servlet-config.xml并没有springmvc元素,因此当服务器启动时,您的控制器甚至并没有被启动。您可以在日志中控制映射,如果它被选中的话。
因此,请尝试使用下面的application-servlet-config.xml,然后查看。如果这不能解决问题,我还建议看一个springmvc教程
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:sec="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<context:annotation-config />
<context:component-scan base-package="your.controller.package" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/Pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>