Quick question, do you have "error.jsp" in your /WEB-INF/view/jsp/
folder?  Also, in your first method
(TestController.testStringResult()) you misspelled "redirect", which
will also result in 404.  Also, take off the leading "/" for the
testModelAndView() and testString()...you're effectively looking for /
WEB-INF/view/jsp//error.jsp (which should still resolve, but is not
necessary and clouds up the code a bit)


Mike!


On May 15, 9:09 pm, jlc488 <jlc...@gmail.com> wrote:
> I've implemented a site using SpringMVC RESTful approaches. I did not
> need any view such as JSP or Velocity and stuff at that time.
>
> For some reason, I needed views using JSPs. Somehow It is showing 404
> not found on JSPs or any views include HTMLs on Google AppEngine.
>
> My requirements are
>
> 1) It should work as RESTful approach which means It returns JSON
> formats of results according to the request. --> working like charm
>
> 2) It should be able to show the JSP result pages on such requests
> like clicking User status confirmation link. --> 404 not found.
>
> I suspect this would be the ViewResolver problems but I have no clue
> about which resolver and how to use it properly.
>
> My configurations are below.
>
> ----------- start of restTask-servlet.xml -------------
>
> <context:annotation-config />
>         <bean
> class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandl 
> erAdapter">
>                 <property name="messageConverters">
>                         <list>
>                                 <ref bean="jsonHttpMessageConverter" />
>                                 <ref bean="stringHttpMessageConverter" />
>                                 <ref bean="formHttpMessageConverter" />
>                         </list>
>                 </property>
>         </bean>
>
>         <bean id="jsonHttpMessageConverter"
> class="org.springframework.http.converter.json.MappingJacksonHttpMessageCon 
> verter"/
>
>
>
>         <bean id="stringHttpMessageConverter"
> class="org.springframework.http.converter.StringHttpMessageConverter" /
>
>
>
>         <bean id="formHttpMessageConverter"
> class="org.springframework.http.converter.FormHttpMessageConverter" />
>
>         <bean
> class="com.otuls.task.view.json.MyContentNegotiatingViewResolver">
>         <property name="mediaTypes">
>         <map>
>         <entry key="html" value="text/html" />
>         <entry key="text" value="text/plain" />
>         <entry key="json" value="application/json" />
>         </map>
>         </property>
>         <property name="defaultContentType" value="application/json" />
>         <property name="defaultViews">
>         <list>
>         <bean class="com.otuls.task.view.json.JsonView" />
>         </list>
>         </property>
>         </bean>
>
>         <bean
>
> class="org.springframework.web.servlet.view.InternalResourceViewResolver">
>                 <property name="order" value="2" />
>                 <property name="prefix" value="/WEB-INF/view/jsp/" />
>                 <property name="suffix" value=".jsp" />
>         </bean>
> ------------- end of restTask-servlet.xml -------------------
>
> ------------- start of JsonView Class -------------------
>
> public class JsonView extends  AbstractView{
>
>         public static final String DEFAULT_CONTENT_TYPE = "application/json";
>
>         private ObjectMapper objectMapper = new ObjectMapper();
>
>         private JsonEncoding encoding = JsonEncoding.UTF8;
>
>         private boolean prefixJson = false;
>
>         private Set<String> renderedAttributes;
>
>         public JsonView() {
>                 setContentType(DEFAULT_CONTENT_TYPE);
>         }
>
>         public void setObjectMapper(ObjectMapper objectMapper) {
>                 Assert.notNull(objectMapper, "'objectMapper' must not be 
> null");
>                 this.objectMapper = objectMapper;
>         }
>
>         public void setEncoding(JsonEncoding encoding) {
>                 Assert.notNull(encoding, "'encoding' must not be null");
>                 this.encoding = encoding;
>         }
>
>         public void setPrefixJson(boolean prefixJson) {
>                 this.prefixJson = prefixJson;
>         }
>
>         /**
>          * Sets the attributes in the model that should be rendered by this
> view. When set, all other model attributes will be
>          * ignored.
>          */
>         public void setRenderedAttributes(Set<String> renderedAttributes) {
>                 this.renderedAttributes = renderedAttributes;
>         }
>
>         @Override
>         protected void prepareResponse(HttpServletRequest request,
> HttpServletResponse response) {
>                 response.setContentType(getContentType());
>                 response.setCharacterEncoding(encoding.getJavaName());
>         }
>
>         @Override
>         protected void renderMergedOutputModel(Map<String, Object> model,
>                         HttpServletRequest request,
>                         HttpServletResponse response) throws Exception {
>                 model = filterModel(model);
>                 JsonGenerator generator =
> objectMapper.getJsonFactory().createJsonGenerator(response.getWriter());
>                 if (prefixJson) {
>                         generator.writeRaw("{} && ");
>                 }
>                 objectMapper.writeValue(generator, model);
>         }
>
>         /**
>          * Filters out undesired attributes from the given model.
>          *
>          * <p>Default implementation removes {@link BindingResult} instances
> and entries not included in the {@link
>          * #setRenderedAttributes(Set) renderedAttributes} property.
>          */
>         protected Map<String, Object> filterModel(Map<String, Object> model)
> {
>                 Map<String, Object> result = new HashMap<String,
> Object>(model.size());
>                 Set<String> renderedAttributes = !
> org.springframework.util.CollectionUtils.isEmpty(this.renderedAttributes) ?
> this.renderedAttributes : model.keySet();
>                 for (Map.Entry<String, Object> entry : model.entrySet()) {
>                         if (!(entry.getValue() instanceof BindingResult) &&
> renderedAttributes.contains(entry.getKey())) {
>                                 result.put(entry.getKey(), entry.getValue());
>                         }
>                 }
>                 return result;
>         }
>
> }
>
> ------------------ end of JsonView class -----------------------
>
> ------------------ start of MyContentNegotiatingViewResolver
> ------------------------
>
> public class MyContentNegotiatingViewResolver extends
>                 ContentNegotiatingViewResolver {
>
>         @Override
>         protected List<MediaType> getMediaTypes(HttpServletRequest request) {
>                 List<MediaType> result = super.getMediaTypes(request);
>         if (result.size() == 1)
>                 result = Arrays.asList(result.get(0));
>         return result;
>         }}
>
> ---------------------- end of MyContentNegotiatingViewResolver
> --------------------------
>
> ----------------------- start of web.xml ---------------------------
>
> <context-param>
>                 <param-name>log4jConfigLocation</param-name>
>                 <param-value>/WEB-INF/log4j.properties</param-value>
>         </context-param>
>         <context-param>
>                 <param-name>contextConfigLocation</param-name>
>                 <param-value>
>                         /WEB-INF/restTask-servlet.xml
>                         /WEB-INF/classes/com/otuls/task/common/config/
> applicationContext.xml
>                         /WEB-INF/classes/com/otuls/task/common/config/aop.xml
>                         
> /WEB-INF/classes/com/otuls/task/common/config/controller.xml
>                         
> /WEB-INF/classes/com/otuls/task/common/config/service.xml
>                         
> /WEB-INF/classes/com/otuls/task/common/config/persistence.xml
>                 </param-value>
>         </context-param>
>
>         <listener>
>                 
> <listener-class>org.springframework.web.util.Log4jConfigListener</
> listener-class>
>         </listener>
>
>         <listener>
>                 <listener-
> class>org.springframework.web.context.ContextLoaderListener</listener-
> class>
>         </listener>
>
>         <servlet>
>                 <servlet-name>restTask</servlet-name>
>                 
> <servlet-class>org.springframework.web.servlet.DispatcherServlet</
> servlet-class>
>                 <init-param>
>                         <param-name>contextConfigLocation</param-name>
>                         <param-value>
>                                 /WEB-INF/restTask-servlet.xml
>                                 /WEB-INF/classes/com/otuls/task/common/config/
> applicationContext.xml
>                                 
> /WEB-INF/classes/com/otuls/task/common/config/aop.xml
>                                 
> /WEB-INF/classes/com/otuls/task/common/config/controller.xml
>                                 
> /WEB-INF/classes/com/otuls/task/common/config/service.xml
>                                 
> /WEB-INF/classes/com/otuls/task/common/config/persistence.xml
>                         </param-value>
>                 </init-param>
>                 <load-on-startup>1</load-on-startup>
>         </servlet>
>
>         <servlet-mapping>
>                 <servlet-name>restTask</servlet-name>
>                 <url-pattern>/*</url-pattern>
>         </servlet-mapping>
>
>         <welcome-file-list>
>                 <welcome-file>index.html</welcome-file>
>         </welcome-file-list>
>
> ---------------------------- end of web.xml
> -------------------------------
>
> --------------------- start of TestController class
> ------------------------
>
> @Controller
> @RequestMapping("/test")
> public class TestController {
>
>         @RequestMapping(value = "/1/", method = RequestMethod.GET)
>         public String testStringResult(){
>                 String tmpLoc = "redicrect:/error";
>                 return tmpLoc;
>         }//testStringResult
>
>         @RequestMapping(value = "/2/", method = RequestMethod.GET)
>         public ModelAndView testModelAndView(){
>                 ModelAndView mav = new ModelAndView();
>
>                 mav.setViewName("/error");
>
>                 return mav;
>         }
>
>         @RequestMapping(value = "/3/", method = RequestMethod.GET)
>         public String testString(){
>                 String tmpLoc = "/error";
>                 return tmpLoc;
>         }
>
> }
>
> --------------------- end of TestController class --------------------
>
> so, If I request URL 
> likehttp://localhost:8080/test/1/,http://localhost:8080/test/2/,http://localhost:8080/test/3/
>
> They all resulting to 404 not found. other RESTful URL approach is
> working fine with current configurations but only JSPs.
>
> Can anyone please help me out on this? or Any Ideas would be
> appreciated.
>
> Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to