jsp部分:<form action="onsend" method="post">
MessageText:<textarea name="message">${time }</textarea>
<input type="submit" value="提交" />
</form>
controller部分: @RequestMapping(value="/onsend",method=RequestMethod.POST)
public ModelAndView producer(@RequestParam("message") String message) {
System.out.println("------------send to jms");
ModelAndView mv = new ModelAndView();
producer.sendMessage(demoQueueDestination, message);
mv.setViewName("welcome");
return mv;
}
配置文件:web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Archetype Created Web Application</display-name>
<!-- 加载spring的配置文件,例如hibernate、jms等集成 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring-root.xml;
classpath:activemq.xml;
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc-dispatch.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- 处理编码格式 -->
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
添加回答
举报
0/150
提交
取消