简体   繁体   English

java ee spring错误

[英]java ee spring error

I am facing a problem, It doesn't redirect to a jsp(HTTP 404) from the controller although I entered correctly a valid url address that can be treated by the controller. 我遇到了一个问题,尽管我正确输入了可以由控制器处理的有效url地址,但它没有从控制器重定向到jsp(HTTP 404)。 Here is my web.xml , the controller and what the debugger shows me. 这是我的web.xml ,控制器以及调试器显示的内容。

I entered http://localhost:8080/AccessControl/produits.aspx 我输入了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 in the controller package 控制器软件包中的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";
    }
}

This is what Debugger shows me. 这就是调试器向我显示的内容。

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'

This is application-servlet-config.xml file: 这是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>

There are couple of issues with your controller. 控制器有几个问题。

  1. Your controller is missing @Controller annotation. 您的控制器缺少@Controller批注。

  2. Your application-servlet-config.xml does not have spring mvc elements, hence your controller is not even being picked up when server starts. 您的application-servlet-config.xml没有spring mvc元素,因此在服务器启动时甚至没有拾取您的控制器。 You can controller mapping in your logs, if its picked up. 您可以在日志中控制映射(如果已映射)。

So try using the below application-servlet-config.xml instead and see. 因此,请尝试使用下面的application-servlet-config.xml来代替。 I would also suggest seeing a spring mvc tutorial, if this does not resolve it. 如果这不能解决问题,我还建议您查看Spring MVC教程。

<?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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM