????????action????????????

 

package test.java.action;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import com.pinfang.logic.service.UserService;
import test.test.JUnitActionBase;
/**
* action????????
* @author fule
*
*/
public class UserActionTest extends JUnitActionBase {
@Autowired UserService service;
@Test
public void testUserShow() throws Exception{
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
request.setServletPath("/userManager/user.show");
request.addParameter("name"?? "????");
request.addParameter("password"?? "123456");
request.setMethod("post");
request.setAttribute("msg"?? "????action???");
final ModelAndView mav = this.excuteAction(request?? response);
Assert.assertEquals("userManager/userlist"?? mav.getViewName());
String msg=(String)request.getAttribute("msg");
System.out.println(msg);
}
}

 

??????????????????????bean:
????<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
????<bean  class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
????Spring???WEB-INF????????????????
???????????????class???£?
????view plaincopyprint?
????ApplicationContext applicationContext = new ClassPathXmlApplicationContext("springMVCForm-servlet.xml");
????WEB-INF?£?
????[java] view plaincopyprint?
????ApplicationContext applicationContext = new FileSystemXmlApplicationContext("WebContent/WEB-INF/springMVCForm-servlet.xml");
??????????????*?????
????[java] view plaincopyprint?
????ApplicationContext applicationContext = new FileSystemXmlApplicationContext("WebContent/WEB-INF/springMVCForm-*.xml");
??????????
???????????????class???£?
????[java] view plaincopyprint?
????@ContextConfiguration(locations={"classpath:springMVCForm-servlet.xml"})
????WEB-INF?£?
????view plaincopyprint?
????@ContextConfiguration(locations={"file:WebContent/WEB-INF/springMVCForm-servlet.xml"})