当前位置: 首页>>代码示例>>Java>>正文


Java View.render方法代码示例

本文整理汇总了Java中org.springframework.web.servlet.View.render方法的典型用法代码示例。如果您正苦于以下问题:Java View.render方法的具体用法?Java View.render怎么用?Java View.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.servlet.View的用法示例。


在下文中一共展示了View.render方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resolveViewNoMatchUseUnacceptableStatus

import org.springframework.web.servlet.View; //导入方法依赖的package包/类
@Test
public void resolveViewNoMatchUseUnacceptableStatus() throws Exception {
	viewResolver.setUseNotAcceptableStatusCode(true);
	request.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9");

	ViewResolver viewResolverMock = mock(ViewResolver.class);
	viewResolver.setViewResolvers(Collections.singletonList(viewResolverMock));

	viewResolver.afterPropertiesSet();

	View viewMock = mock(View.class, "application_xml");

	String viewName = "view";
	Locale locale = Locale.ENGLISH;

	given(viewResolverMock.resolveViewName(viewName, locale)).willReturn(viewMock);
	given(viewMock.getContentType()).willReturn("application/pdf");

	View result = viewResolver.resolveViewName(viewName, locale);
	assertNotNull("Invalid view", result);
	MockHttpServletResponse response = new MockHttpServletResponse();
	result.render(null, request, response);
	assertEquals("Invalid status code set", 406, response.getStatus());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:ContentNegotiatingViewResolverTests.java

示例2: doGet

import org.springframework.web.servlet.View; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    if (!inited) {
        LOG.error("spring freemarker servlet 未初始化");
        resp.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
        resp.getWriter().write("spring freemarker servlet no init");
        return;
    }

    try {
        String requestUri = req.getRequestURI();
        String templatePath = requestUri.substring(0, requestUri.length() - suffix.length());
        View view = freeMarkerViewResolver.resolveViewName(templatePath, req.getLocale());
        view.render(null, req, resp);
    } catch (Exception e) {
        resp.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
        e.printStackTrace(new PrintStream(resp.getOutputStream()));
    }
}
 
开发者ID:kevin70,项目名称:setaria,代码行数:20,代码来源:SpringFreeMarkerServlet.java

示例3: doTestUrlBasedViewResolverWithoutPrefixes

import org.springframework.web.servlet.View; //导入方法依赖的package包/类
private void doTestUrlBasedViewResolverWithoutPrefixes(UrlBasedViewResolver vr) throws Exception {
	StaticWebApplicationContext wac = new StaticWebApplicationContext();
	wac.setServletContext(new MockServletContext());
	wac.refresh();
	vr.setApplicationContext(wac);
	vr.setContentType("myContentType");
	vr.setRequestContextAttribute("rc");

	View view = vr.resolveViewName("example1", Locale.getDefault());
	assertEquals("Correct view class", JstlView.class, view.getClass());
	assertEquals("Correct URL", "example1", ((InternalResourceView) view).getUrl());
	assertEquals("Correct textContentType", "myContentType", ((InternalResourceView) view).getContentType());

	view = vr.resolveViewName("example2", Locale.getDefault());
	assertEquals("Correct view class", JstlView.class, view.getClass());
	assertEquals("Correct URL", "example2", ((InternalResourceView) view).getUrl());
	assertEquals("Correct textContentType", "myContentType", ((InternalResourceView) view).getContentType());

	HttpServletRequest request = new MockHttpServletRequest(wac.getServletContext());
	HttpServletResponse response = new MockHttpServletResponse();
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
	request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
	Map model = new HashMap();
	TestBean tb = new TestBean();
	model.put("tb", tb);
	view.render(model, request, response);
	assertTrue("Correct tb attribute", tb.equals(request.getAttribute("tb")));
	assertTrue("Correct rc attribute", request.getAttribute("rc") instanceof RequestContext);

	view = vr.resolveViewName("redirect:myUrl", Locale.getDefault());
	assertEquals("Correct view class", RedirectView.class, view.getClass());
	assertEquals("Correct URL", "myUrl", ((RedirectView) view).getUrl());
	assertSame("View not initialized as bean", wac, ((RedirectView) view).getApplicationContext());

	view = vr.resolveViewName("forward:myUrl", Locale.getDefault());
	assertEquals("Correct view class", InternalResourceView.class, view.getClass());
	assertEquals("Correct URL", "myUrl", ((InternalResourceView) view).getUrl());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:40,代码来源:ViewResolverTests.java

示例4: testInternalResourceViewResolverWithContextBeans

import org.springframework.web.servlet.View; //导入方法依赖的package包/类
@Test
public void testInternalResourceViewResolverWithContextBeans() throws Exception {
	MockServletContext sc = new MockServletContext();
	final StaticWebApplicationContext wac = new StaticWebApplicationContext();
	wac.registerSingleton("myBean", TestBean.class);
	wac.registerSingleton("myBean2", TestBean.class);
	wac.setServletContext(sc);
	wac.refresh();
	InternalResourceViewResolver vr = new InternalResourceViewResolver();
	Properties props = new Properties();
	props.setProperty("key1", "value1");
	vr.setAttributes(props);
	Map map = new HashMap();
	map.put("key2", new Integer(2));
	vr.setAttributesMap(map);
	vr.setExposeContextBeansAsAttributes(true);
	vr.setApplicationContext(wac);

	MockHttpServletRequest request = new MockHttpServletRequest(sc) {
		@Override
		public RequestDispatcher getRequestDispatcher(String path) {
			return new MockRequestDispatcher(path) {
				@Override
				public void forward(ServletRequest forwardRequest, ServletResponse forwardResponse) {
					assertTrue("Correct rc attribute", forwardRequest.getAttribute("rc") == null);
					assertEquals("value1", forwardRequest.getAttribute("key1"));
					assertEquals(new Integer(2), forwardRequest.getAttribute("key2"));
					assertSame(wac.getBean("myBean"), forwardRequest.getAttribute("myBean"));
					assertSame(wac.getBean("myBean2"), forwardRequest.getAttribute("myBean2"));
				}
			};
		}
	};
	HttpServletResponse response = new MockHttpServletResponse();
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
	View view = vr.resolveViewName("example1", Locale.getDefault());
	view.render(new HashMap(), request, response);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:40,代码来源:ViewResolverTests.java

示例5: testInternalResourceViewResolverWithSpecificContextBeans

import org.springframework.web.servlet.View; //导入方法依赖的package包/类
@Test
public void testInternalResourceViewResolverWithSpecificContextBeans() throws Exception {
	MockServletContext sc = new MockServletContext();
	final StaticWebApplicationContext wac = new StaticWebApplicationContext();
	wac.registerSingleton("myBean", TestBean.class);
	wac.registerSingleton("myBean2", TestBean.class);
	wac.setServletContext(sc);
	wac.refresh();
	InternalResourceViewResolver vr = new InternalResourceViewResolver();
	Properties props = new Properties();
	props.setProperty("key1", "value1");
	vr.setAttributes(props);
	Map map = new HashMap();
	map.put("key2", new Integer(2));
	vr.setAttributesMap(map);
	vr.setExposedContextBeanNames(new String[] {"myBean2"});
	vr.setApplicationContext(wac);

	MockHttpServletRequest request = new MockHttpServletRequest(sc) {
		@Override
		public RequestDispatcher getRequestDispatcher(String path) {
			return new MockRequestDispatcher(path) {
				@Override
				public void forward(ServletRequest forwardRequest, ServletResponse forwardResponse) {
					assertTrue("Correct rc attribute", forwardRequest.getAttribute("rc") == null);
					assertEquals("value1", forwardRequest.getAttribute("key1"));
					assertEquals(new Integer(2), forwardRequest.getAttribute("key2"));
					assertNull(forwardRequest.getAttribute("myBean"));
					assertSame(wac.getBean("myBean2"), forwardRequest.getAttribute("myBean2"));
				}
			};
		}
	};
	HttpServletResponse response = new MockHttpServletResponse();
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
	View view = vr.resolveViewName("example1", Locale.getDefault());
	view.render(new HashMap(), request, response);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:40,代码来源:ViewResolverTests.java

示例6: testInternalResourceViewResolverWithJstl

import org.springframework.web.servlet.View; //导入方法依赖的package包/类
@Test
public void testInternalResourceViewResolverWithJstl() throws Exception {
	Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH;

	MockServletContext sc = new MockServletContext();
	StaticWebApplicationContext wac = new StaticWebApplicationContext();
	wac.setServletContext(sc);
	wac.addMessage("code1", locale, "messageX");
	wac.refresh();
	InternalResourceViewResolver vr = new InternalResourceViewResolver();
	vr.setViewClass(JstlView.class);
	vr.setApplicationContext(wac);

	View view = vr.resolveViewName("example1", Locale.getDefault());
	assertEquals("Correct view class", JstlView.class, view.getClass());
	assertEquals("Correct URL", "example1", ((JstlView) view).getUrl());

	view = vr.resolveViewName("example2", Locale.getDefault());
	assertEquals("Correct view class", JstlView.class, view.getClass());
	assertEquals("Correct URL", "example2", ((JstlView) view).getUrl());

	MockHttpServletRequest request = new MockHttpServletRequest(sc);
	HttpServletResponse response = new MockHttpServletResponse();
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(locale));
	Map model = new HashMap();
	TestBean tb = new TestBean();
	model.put("tb", tb);
	view.render(model, request, response);

	assertTrue("Correct tb attribute", tb.equals(request.getAttribute("tb")));
	assertTrue("Correct rc attribute", request.getAttribute("rc") == null);

	assertEquals(locale, Config.get(request, Config.FMT_LOCALE));
	LocalizationContext lc = (LocalizationContext) Config.get(request, Config.FMT_LOCALIZATION_CONTEXT);
	assertEquals("messageX", lc.getResourceBundle().getString("code1"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:38,代码来源:ViewResolverTests.java

示例7: testInternalResourceViewResolverWithJstlAndContextParam

import org.springframework.web.servlet.View; //导入方法依赖的package包/类
@Test
public void testInternalResourceViewResolverWithJstlAndContextParam() throws Exception {
	Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH;

	MockServletContext sc = new MockServletContext();
	sc.addInitParameter(Config.FMT_LOCALIZATION_CONTEXT, "org/springframework/web/context/WEB-INF/context-messages");
	StaticWebApplicationContext wac = new StaticWebApplicationContext();
	wac.setServletContext(sc);
	wac.addMessage("code1", locale, "messageX");
	wac.refresh();
	InternalResourceViewResolver vr = new InternalResourceViewResolver();
	vr.setViewClass(JstlView.class);
	vr.setApplicationContext(wac);

	View view = vr.resolveViewName("example1", Locale.getDefault());
	assertEquals("Correct view class", JstlView.class, view.getClass());
	assertEquals("Correct URL", "example1", ((JstlView) view).getUrl());

	view = vr.resolveViewName("example2", Locale.getDefault());
	assertEquals("Correct view class", JstlView.class, view.getClass());
	assertEquals("Correct URL", "example2", ((JstlView) view).getUrl());

	MockHttpServletRequest request = new MockHttpServletRequest(sc);
	HttpServletResponse response = new MockHttpServletResponse();
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(locale));
	Map model = new HashMap();
	TestBean tb = new TestBean();
	model.put("tb", tb);
	view.render(model, request, response);

	assertTrue("Correct tb attribute", tb.equals(request.getAttribute("tb")));
	assertTrue("Correct rc attribute", request.getAttribute("rc") == null);

	assertEquals(locale, Config.get(request, Config.FMT_LOCALE));
	LocalizationContext lc = (LocalizationContext) Config.get(request, Config.FMT_LOCALIZATION_CONTEXT);
	assertEquals("message1", lc.getResourceBundle().getString("code1"));
	assertEquals("message2", lc.getResourceBundle().getString("code2"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:40,代码来源:ViewResolverTests.java

示例8: render

import org.springframework.web.servlet.View; //导入方法依赖的package包/类
private MockHttpServletResponse render(String viewName) throws Exception {
	FreeMarkerViewResolver resolver = this.context
			.getBean(FreeMarkerViewResolver.class);
	View view = resolver.resolveViewName(viewName, Locale.UK);
	assertThat(view).isNotNull();
	HttpServletRequest request = new MockHttpServletRequest();
	request.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE,
			this.context);
	MockHttpServletResponse response = new MockHttpServletResponse();
	view.render(null, request, response);
	return response;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:FreeMarkerAutoConfigurationTests.java

示例9: render

import org.springframework.web.servlet.View; //导入方法依赖的package包/类
private MockHttpServletResponse render(String viewName, Locale locale)
		throws Exception {
	LocaleContextHolder.setLocale(locale);
	GroovyMarkupViewResolver resolver = this.context
			.getBean(GroovyMarkupViewResolver.class);
	View view = resolver.resolveViewName(viewName, locale);
	assertThat(view).isNotNull();
	HttpServletRequest request = new MockHttpServletRequest();
	request.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE,
			this.context);
	MockHttpServletResponse response = new MockHttpServletResponse();
	view.render(null, request, response);
	return response;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:15,代码来源:GroovyTemplateAutoConfigurationTests.java

示例10: render

import org.springframework.web.servlet.View; //导入方法依赖的package包/类
private MockHttpServletResponse render(String viewName) throws Exception {
	VelocityViewResolver resolver = this.context.getBean(VelocityViewResolver.class);
	View view = resolver.resolveViewName(viewName, Locale.UK);
	assertThat(view).isNotNull();
	HttpServletRequest request = new MockHttpServletRequest();
	request.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE,
			this.context);
	MockHttpServletResponse response = new MockHttpServletResponse();
	view.render(null, request, response);
	return response;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:VelocityAutoConfigurationTests.java

示例11: evalView

import org.springframework.web.servlet.View; //导入方法依赖的package包/类
public String evalView(HttpServletRequest request,
		HttpServletResponse response, Map<String, Object> model,
		Locale locale, String viewName) throws Exception {
	CustomHttpServletResponse customResponse = new CustomHttpServletResponse(
			response);
	View view = viewResolver.resolveViewName(viewName, locale);
	if (view != null) {
		view.render(model, request, customResponse);
		OutputStream os = customResponse.getOutputStream();
		return os.toString();
	}
	throw new Exception("no view found");
}
 
开发者ID:petabyte-research,项目名称:redflags,代码行数:14,代码来源:InternalRenderer.java

示例12: testInternalResourceViewResolverWithAttributes

import org.springframework.web.servlet.View; //导入方法依赖的package包/类
@Test
public void testInternalResourceViewResolverWithAttributes() throws Exception {
	MockServletContext sc = new MockServletContext();
	StaticWebApplicationContext wac = new StaticWebApplicationContext();
	wac.setServletContext(sc);
	wac.refresh();
	InternalResourceViewResolver vr = new InternalResourceViewResolver();
	Properties props = new Properties();
	props.setProperty("key1", "value1");
	vr.setAttributes(props);
	Map map = new HashMap();
	map.put("key2", new Integer(2));
	vr.setAttributesMap(map);
	vr.setApplicationContext(wac);

	View view = vr.resolveViewName("example1", Locale.getDefault());
	assertEquals("Correct view class", JstlView.class, view.getClass());
	assertEquals("Correct URL", "example1", ((InternalResourceView) view).getUrl());
	Map attributes = ((InternalResourceView) view).getStaticAttributes();
	assertEquals("value1", attributes.get("key1"));
	assertEquals(new Integer(2), attributes.get("key2"));

	view = vr.resolveViewName("example2", Locale.getDefault());
	assertEquals("Correct view class", JstlView.class, view.getClass());
	assertEquals("Correct URL", "example2", ((InternalResourceView) view).getUrl());
	attributes = ((InternalResourceView) view).getStaticAttributes();
	assertEquals("value1", attributes.get("key1"));
	assertEquals(new Integer(2), attributes.get("key2"));

	MockHttpServletRequest request = new MockHttpServletRequest(sc);
	HttpServletResponse response = new MockHttpServletResponse();
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
	Map model = new HashMap();
	TestBean tb = new TestBean();
	model.put("tb", tb);
	view.render(model, request, response);

	assertTrue("Correct tb attribute", tb.equals(request.getAttribute("tb")));
	assertTrue("Correct rc attribute", request.getAttribute("rc") == null);
	assertEquals("value1", request.getAttribute("key1"));
	assertEquals(new Integer(2), request.getAttribute("key2"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:44,代码来源:ViewResolverTests.java

示例13: testXmlViewResolver

import org.springframework.web.servlet.View; //导入方法依赖的package包/类
@Test
public void testXmlViewResolver() throws Exception {
	StaticWebApplicationContext wac = new StaticWebApplicationContext();
	wac.registerSingleton("testBean", TestBean.class);
	wac.setServletContext(new MockServletContext());
	wac.refresh();
	TestBean testBean = (TestBean) wac.getBean("testBean");
	XmlViewResolver vr = new XmlViewResolver();
	vr.setLocation(new ClassPathResource("org/springframework/web/servlet/view/views.xml"));
	vr.setApplicationContext(wac);

	View view1 = vr.resolveViewName("example1", Locale.getDefault());
	assertTrue("Correct view class", TestView.class.equals(view1.getClass()));
	assertTrue("Correct URL", "/example1.jsp".equals(((InternalResourceView) view1).getUrl()));

	View view2 = vr.resolveViewName("example2", Locale.getDefault());
	assertTrue("Correct view class", JstlView.class.equals(view2.getClass()));
	assertTrue("Correct URL", "/example2new.jsp".equals(((InternalResourceView) view2).getUrl()));

	ServletContext sc = new MockServletContext();
	Map model = new HashMap();
	TestBean tb = new TestBean();
	model.put("tb", tb);

	HttpServletRequest request = new MockHttpServletRequest(sc);
	HttpServletResponse response = new MockHttpServletResponse();
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
	request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
	view1.render(model, request, response);
	assertTrue("Correct tb attribute", tb.equals(request.getAttribute("tb")));
	assertTrue("Correct test1 attribute", "testvalue1".equals(request.getAttribute("test1")));
	assertTrue("Correct test2 attribute", testBean.equals(request.getAttribute("test2")));

	request = new MockHttpServletRequest(sc);
	response = new MockHttpServletResponse();
	request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
	request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
	request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
	view2.render(model, request, response);
	assertTrue("Correct tb attribute", tb.equals(request.getAttribute("tb")));
	assertTrue("Correct test1 attribute", "testvalue1".equals(request.getAttribute("test1")));
	assertTrue("Correct test2 attribute", "testvalue2".equals(request.getAttribute("test2")));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:45,代码来源:ViewResolverTests.java


注:本文中的org.springframework.web.servlet.View.render方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。