小编use*_*786的帖子

SpringMVC和静态资源

我是java和spring的新手.我正在尝试制作你好世界的应用程序而不会得到我做错了什么.

这是我的目录结构:

test_app
-pom.xml
-src
--main
---java
----com.example.web
-----IndexController.java
---webapp
----static
-----img
------example.jpg
----WEB-INF
-----web.xml
-----dispatcher-servlet.xml
-----jsp
------index.jsp
Run Code Online (Sandbox Code Playgroud)

和来源:web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC
        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         id="WebApp_ID" version="2.5">

    <display-name>Movie Reminder WebApp</display-name>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>WEB-INF/dispatcher-servlet.xml</param-value>
    </context-param>
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
</web-app>
Run Code Online (Sandbox Code Playgroud)

调度员servlet.xml中:

<?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:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> …
Run Code Online (Sandbox Code Playgroud)

java rest spring-mvc tomcat7

9
推荐指数
2
解决办法
2万
查看次数

从jsp文件中删除大型开关的正确方法是什么

从JSP文件中删除switch的正确方法是什么?我有一个工厂,可以返回多种类型的对象.每个都有自己的表示逻辑,所以我需要这样的东西:

//From controller
@RequestMapping(value = "/source", method = RequestMethod.POST)
public ModelAndView doMainJob(@RequestParam("text") String text) {
    ResultState state = new ResultStateFactory().fromString(text);
    ModelAndView model = new ModelAndView("result/view");
    model.addObject("state", state);
    model.addObject("stateType", state.getClass());
    return model;
}

//from jsp/result/view.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="main"  tagdir="/WEB-INF/tags" %>
<%@taglib prefix="r"  tagdir="/WEB-INF/tags/result" %>
<main:basic_layout>
  <jsp:body>
    <c:choose>
      <c:when test="${stateType == StateA}"><r:stateA param=${state} /></c:when>
      <c:when test="${stateType == StateB}"><r:stateB param=${state} /></c:when>
      <c:when test="${stateType == StateC}"><r:stateC param=${state} /></c:when>
      .
      .
      .
      <c:when test="${stateType == StateX}"><r:stateX param=${state} /></c:when>
      <c:when test="${stateType == StateY}"><r:stateY param=${state} …
Run Code Online (Sandbox Code Playgroud)

java tags jsp factory

5
推荐指数
1
解决办法
187
查看次数

标签 统计

java ×2

factory ×1

jsp ×1

rest ×1

spring-mvc ×1

tags ×1

tomcat7 ×1