阿录帮帮忙—spring mvc 的hello world
2015-12-18 10:43
387 查看
一:web.xml配置
<!-- Spring MVC配置 --> <servlet> <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <pre name="code" class="html"> <!-- 相应的mvc配置文件地址: --><param-value>/WEB-INF/conf/web-application-config.xml</param-value></init-param> </servlet> <servlet-mapping><servlet-name>Spring MVC Dispatcher Servlet</servlet-name><url-pattern>*.do</url-pattern> </servlet-mapping>
二:mvc配置文件
<?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.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!-- 默认扫描的包路径 --> <context:component-scan base-package="com.sofmit.psa"/> <!-- 加入注解驱动 --> <mvc:annotation-driven/> <!-- 定义跳转的文件的前后缀 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <!-- 默认转向页面后缀 --> <property name="suffix" value=".jsp" /> </bean> </beans>三:后台代码
package com.sofmit.psa.central.test.test; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping("/central/test") public class TestAction { @RequestMapping("/test") public String test(){ return "/test"; } }四:前台代码
<? xml version="1.0" encoding="UTF-8" ?> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Insert title here</title> </head> <body> HELLO WORLD。! !! !!。! !。!! 。。!!!!! !! </body> </html>
相关文章推荐
- 轉:JAVA多態
- 如何将jdk1.8降到jdk1.6
- SpringMvc(Base64解密)上传
- Java中堆内存和栈内存详解
- eclipse项目导入到Android Studio Plugin with id 'android-library' not found
- java方法重载 与 重写
- JAVA中关于进制间的相互转换
- Find the duplicate Number (鸽巢原理) leetcode java
- 【Java EE 学习 74 上】【数据采集系统第六天】【使用Jfreechart的统计图实现】【Jfreechart的基本使用方法】
- eclipse安装svn插件
- 为什么HikariCP被号称为性能最好的Java数据库连接池,如何配置使用
- Spring 简单读取文件
- java 读取 写入 csv 文件
- JAVA / Scala Multi Class in One Source File
- 轻量级JavaEE企业应用实战(八)
- java Semaphore(信号量)
- Java后台如何接收并处理前台传过来的json格式的数组参数
- Java计算上传文件大小
- Binary Tree Level Order Traversal - leetcode - java
- Top 16 Java 应用类 - 这些功能再也不用自己写了