Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    [JAVA - SPRING Framework] Problema per newbie

    Salve a tutti...ho un probkema e vi giuro che sto impazzendo.Ho provato a fare una piccola web application molto banale:

    Sto utilizzando il framework Spring.

    In una pagina jsp l'utente deve inserire due valori,e la web application dovrebbe restituirne la somma(insomma...robba da veri smanettoni uauaua).

    ApplicationContext.xml
    codice:
    <?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:p="http://www.springframework.org/schema/p"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.5.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-2.5.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schem...ing-tx-2.5.xsd">
        
        <!--bean id="propertyConfigurer"
              class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
              p:location="/WEB-INF/jdbc.properties" />
        
        <bean id="dataSource"
              class="org.springframework.jdbc.datasource.DriverManagerDataSource"
              p:driverClassName="${jdbc.driverClassName}"
              p:url="${jdbc.url}"
              p:username="${jdbc.username}"
              p:password="${jdbc.password}" /-->
    
        <bean name="sommaService" class="service.SommaService"/>
        
        
    
        
        
    </beans>
    Dispatcher-servlet.xml:

    codice:
    <?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:p="http://www.springframework.org/schema/p"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.5.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-2.5.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schem...ing-tx-2.5.xsd">
        
        <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
        
        <!--
        Most controllers will use the ControllerClassNameHandlerMapping above, but
        for the index controller we are using ParameterizableViewController, so we must
        define an explicit mapping for it.
        -->
        <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="mappings">
                <props>
                    <prop key="index.htm">indexController</prop>
                </props>
            </property>
        </bean>
        
        <bean id="viewResolver"
              class="org.springframework.web.servlet.view.InternalResourceViewResolver"
              p:prefix="/WEB-INF/jsp/"
              p:suffix=".jsp" />
        
        <!--
        The index controller.
        -->
        <bean name="indexController"
              class="org.springframework.web.servlet.mvc.ParameterizableViewController"
              p:viewName="index" />
    
        <bean class="controller.SommaController" p:sommaService-ref="sommaService"/>
        
    </beans>
    Classe di servizio: SommaService.java appartenente al pacchetto: service

    codice:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package service;
    
    
    /**
     *
     * @author javacomelava
     */
    public class SommaService {
    
        private int sum;
    
        public String comunicaSomma(int a,int b){
            sum=a+b;
            return "La sommma e': "+sum;
        }
    
    }
    Classe di controllo: SommaController.java pacchetto: controller
    codice:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package controller;
    
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.SimpleFormController;
    import service.SommaService;
    
    /** 
     *
     * @author javacomelava
     */
    public class SommaController extends SimpleFormController { 
    
        private SommaService ss;
    
        public SommaController() {
            //Initialize controller properties here or 
            //in the Web Application Context
    
            setCommandClass(Coppia.class);
            setCommandName("coppia");
            setSuccessView("sommaView");
            setFormView("sommaForm");
        }
    
        public void setSommaService(SommaService somser){
            ss=somser;
        }
        
    
        //Use onSubmit instead of doSubmitAction 
        //when you need access to the Request, Response, or BindException objects
        
        @Override
        protected ModelAndView onSubmit(Object command) throws Exception {
            Coppia cp=(Coppia)command;
            ModelAndView mv = new ModelAndView(getSuccessView());
            mv.addObject("sommaSystem",ss.comunicaSomma(cp.getX(),cp.getY()));
            return mv;
        }
        
    
    }
    JavaBean: Coppia.java pacchetto: controller

    codice:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package controller;
    
    /**
     *
     * @author javacomelava
     */
    public class Coppia {
    
        private int x;
        private int y;
    
        public int getX(){
            return x;
        }
    
        public int getY(){
            return y;
        }
    
        public void setX(int a){
            x=a;
        }
    
        public void setY(int b){
            y=b;
        }
    }

    Quando provo a far partire il progetto Tomcat mi da questo errore(che ho postato su FriendPaste essendo molto lungo):

    http://www.friendpaste.com/4tPwo5FpHMBqTUBVhr7pev

    .....dice che non trova la classe SommaController,ma è li'....

    grazie per l'attenzione

  2. #2
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,466

    Moderazione

    Ho spostato la discussione nel forum dedicato a Java.
    In futuro, poni qui le tue domande relative a questo linguaggio.

    Ciao!
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.