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