- 浏览: 543050 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (278)
- freemarker (6)
- flex应用 (12)
- Ext应用 (11)
- 软件 (16)
- java (61)
- 报表 (6)
- 框架基础 (6)
- 登录页面素材 (7)
- oracle (1)
- cas (10)
- lucene (6)
- linux (11)
- 视频 (10)
- springmvc (3)
- 视频服务器相关 (12)
- 开发工具 (7)
- IOS (20)
- 网站相关 (4)
- Java 任务调度系统带图形界面的 (1)
- maven (2)
- android (29)
- hadoop (3)
- SpagoBI (3)
- docx4j (4)
- 多线程 (2)
- storm (2)
- mobile 框架 (3)
- scala (1)
- socket (1)
- saiku (1)
最新评论
-
ZXCLTN:
1.streams目录,在里面放些flv,mp3之类的文件,这 ...
red5 整合到tomcat中(二) -
ZXCLTN:
写的没偷没尾的,还不如提供整个项目下载
red5 整合到tomcat中(二) -
01jiangwei01:
测试方法1:测试50个线 ...
hibernate 乐观锁 测试 -
01jiangwei01:
测试方法1:测试50个线程,同时并发访问。目标:只有一个通过, ...
hibernate 乐观锁 测试 -
xiaobadi:
你每次登陆都是跳到http://localhost:8081/ ...
cas 系统实例 服务端配置(二) 自定义登录
最近做springmvc注解操作,终于实验成功,可以跑动了。今天把代码贴出来,希望大家帮我继续晚上
清单一:web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/*.xml</param-value>
</context-param>
<!-- 设置Spring监听器 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- springmvc 配置 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
<!-- springmvc 配置结束 -->
<!-- DWR servlet 配置结束 -->
<!-- 著名的 Character Encoding filter -->
<filter>
<filter-name>encodingFilter</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>
</filter>
<!--Hibernate Open Session in View Filter-->
<!-- 假设在你的应用中Hibernate是通过spring 来管理它的session.如果在你的应用中没有使用OpenSessionInViewFilter
或者OpenSessionInViewInterceptor。session会在transaction结束后关闭,此时会抛出session is close 的异常-->
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<!-- 过滤器映射 -->
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 扩展spring bean的作用域有request,session,global session等-->
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<!-- Spring 刷新Introspector防止内存泄露 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
</web-app>
清单2:WEB-INF/springmvc-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
修改说明:
1.修改<context:component-scan以确定要加载的controller,默认为com.**.controller
2.修改class=ControllerClassNameHandlerMapping节点的pathPrefix以确定要生成的前缀
-->
<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:dwr="http://www.directwebremoting.org/schema/spring-dwr"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.directwebremoting.org/schema/spring-dwr
http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd"
default-autowire="byName" >
<context:annotation-config />
<!-- ②:启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>
<!-- ③:对模型视图名称的解析,即在模型视图名称添加前后缀
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="view/" p:suffix=".jsp" />
-->
<!-- 注意这里新增加的dwr tag, 为使其生效,文件头中要声明namespace -->
<dwr:configuration />
<dwr:annotation-config />
<dwr:url-mapping />
<!-- 部署项目时, 请把debug设为false -->
<dwr:controller id="dwrController" debug="true" />
<!--①:规约所有进行扫描的类,以完成Bean创建和自动依赖注入的功能-->
<!-- component-scan自动搜索@Component , @Controller , @Service , @Repository等标注的类 -->
<context:component-scan base-package="com.**.controller"/>
<!-- order值越小, 优先级越高 -->
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="order" value="1" />
</bean>
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
<property name="order" value="2" />
</bean>
<!-- 文件上传-->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
p:defaultEncoding="utf-8" />
</beans>
清单三:src/spring/applicationContext.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/baoxian?useUnicode=true&amp;characterEncoding=UTF-8">
</property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
</bean></beans>
清单四:src/spring/appapplicationContext-dao.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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-autowire="byName" default-lazy-init="false">
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- Transaction manager for a single JDBC DataSource -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- component-scan自动搜索@Component , @Controller , @Service , @Repository等标注的类 -->
<context:component-scan base-package="com.**.dao"/>
</beans>
清单五:src/spring/applicationContext-service.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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd" default-autowire="byName" default-lazy-init="false">
<!-- component-scan自动搜索@Component , @Controller , @Service , @Repository等标注的类 -->
<!-- 默认值如果适合,该项可以不用修改 -->
<context:component-scan base-package="com.**.service" />
</beans>
清单六 SysmodelDao.java
package com.baoxian.dao;
import java.util.ArrayList;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Component;
import com.baoxian.entity.Sysmodel;
@Component("sysmodelDao")
public class SysmodelDao extends HibernateDaoSupport {
public List find2(String hsql)
{
System.out.println("执行dao");
List ls = new ArrayList();
Sysmodel su = new Sysmodel();
su.setSysmodelId("1111111111");
ls.add(su);
return ls;
}
}
清单七DemoControler.java
package com.baoxian.controller;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baoxian.dao.SysmodelDao;
@Controller
@RequestMapping("/demo/demo.htm")
public class DemoControler {
@Autowired
@Qualifier("sysmodelDao")
private SysmodelDao dao;;
@RequestMapping(params = "method=test")
public String listBoardTopic(HttpServletRequest request,HttpServletResponse response,ModelMap model) {
System.out.println("have got the login function");
String loginsuccessdir = "/demo/successful.jsp";
String logingfaulsedir = "/demo/noSuccessful.jsp";
String username = request.getParameter("username");
String pwd = request.getParameter("userpassword");
System.out.println("username="+username);
System.out.println("pwd="+pwd);
List ls =dao.find2("");
System.out.println("---------------------");
System.out.println(ls.size());
if(username==null||"".equals(username))
{
return logingfaulsedir ;
}
return loginsuccessdir;
}
}
清单 八Dwr2Controller.java
package com.baoxian.controller;
import org.directwebremoting.annotations.RemoteMethod;
import org.directwebremoting.annotations.RemoteProxy;
import org.springframework.stereotype.Controller;
@Controller
@RemoteProxy(name="Dwr2Controller")
public class Dwr2Controller {
@RemoteMethod
public String getUserName(int id) {
System.out.println("user id is " + id);
return "UserName: " + id;
}
}
清单九 测试页面demo.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>controller_test.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<form action="demo.htm" method='post'>
<input type="hidden" name='method' value='test'>
<table>
<tr><td>用户名:</td><td><input type="text" name="username"/></td></tr>
<tr><td>密码:</td><td><input type="text" name="userpassword"/></td></tr>
<tr><td><input type="submit" value="确定"/></td><td><input type="reset" value="取消"/></td></tr>
</table>
</form>
</body>
</html>
清单十 测试页面webRoot/demo/dwrtest.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>controller_dwr.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type='text/javascript' src='../dwr/util.js'></script>
<script type='text/javascript' src='../dwr/engine.js'></script>
<script type='text/javascript' src='../dwr/interface/Dwr2Controller.js'> </script>
</head>
<script type="text/javascript">
function dwrfn()
{
Dwr2Controller.getUserName("1",callBackHello);
}
function callBackHello(data)
{
alert(data);
}
</script>
<body>
<input type ='button' value="click me to test" onclick="dwrfn()"/>
</body>
</html>
清单十一 测试结果页面webRoot/demo/successful.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'successful.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
This is successful page. <br>
</body>
</html>
清单一:web.xml
引用
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/*.xml</param-value>
</context-param>
<!-- 设置Spring监听器 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- springmvc 配置 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
<!-- springmvc 配置结束 -->
<!-- DWR servlet 配置结束 -->
<!-- 著名的 Character Encoding filter -->
<filter>
<filter-name>encodingFilter</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>
</filter>
<!--Hibernate Open Session in View Filter-->
<!-- 假设在你的应用中Hibernate是通过spring 来管理它的session.如果在你的应用中没有使用OpenSessionInViewFilter
或者OpenSessionInViewInterceptor。session会在transaction结束后关闭,此时会抛出session is close 的异常-->
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<!-- 过滤器映射 -->
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 扩展spring bean的作用域有request,session,global session等-->
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<!-- Spring 刷新Introspector防止内存泄露 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
</web-app>
清单2:WEB-INF/springmvc-servlet.xml
引用
<?xml version="1.0" encoding="UTF-8"?>
<!--
修改说明:
1.修改<context:component-scan以确定要加载的controller,默认为com.**.controller
2.修改class=ControllerClassNameHandlerMapping节点的pathPrefix以确定要生成的前缀
-->
<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:dwr="http://www.directwebremoting.org/schema/spring-dwr"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.directwebremoting.org/schema/spring-dwr
http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd"
default-autowire="byName" >
<context:annotation-config />
<!-- ②:启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>
<!-- ③:对模型视图名称的解析,即在模型视图名称添加前后缀
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="view/" p:suffix=".jsp" />
-->
<!-- 注意这里新增加的dwr tag, 为使其生效,文件头中要声明namespace -->
<dwr:configuration />
<dwr:annotation-config />
<dwr:url-mapping />
<!-- 部署项目时, 请把debug设为false -->
<dwr:controller id="dwrController" debug="true" />
<!--①:规约所有进行扫描的类,以完成Bean创建和自动依赖注入的功能-->
<!-- component-scan自动搜索@Component , @Controller , @Service , @Repository等标注的类 -->
<context:component-scan base-package="com.**.controller"/>
<!-- order值越小, 优先级越高 -->
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="order" value="1" />
</bean>
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
<property name="order" value="2" />
</bean>
<!-- 文件上传-->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
p:defaultEncoding="utf-8" />
</beans>
清单三:src/spring/applicationContext.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/baoxian?useUnicode=true&amp;characterEncoding=UTF-8">
</property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
</bean></beans>
清单四:src/spring/appapplicationContext-dao.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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-autowire="byName" default-lazy-init="false">
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- Transaction manager for a single JDBC DataSource -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- component-scan自动搜索@Component , @Controller , @Service , @Repository等标注的类 -->
<context:component-scan base-package="com.**.dao"/>
</beans>
清单五:src/spring/applicationContext-service.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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd" default-autowire="byName" default-lazy-init="false">
<!-- component-scan自动搜索@Component , @Controller , @Service , @Repository等标注的类 -->
<!-- 默认值如果适合,该项可以不用修改 -->
<context:component-scan base-package="com.**.service" />
</beans>
清单六 SysmodelDao.java
引用
package com.baoxian.dao;
import java.util.ArrayList;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Component;
import com.baoxian.entity.Sysmodel;
@Component("sysmodelDao")
public class SysmodelDao extends HibernateDaoSupport {
public List find2(String hsql)
{
System.out.println("执行dao");
List ls = new ArrayList();
Sysmodel su = new Sysmodel();
su.setSysmodelId("1111111111");
ls.add(su);
return ls;
}
}
清单七DemoControler.java
引用
package com.baoxian.controller;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baoxian.dao.SysmodelDao;
@Controller
@RequestMapping("/demo/demo.htm")
public class DemoControler {
@Autowired
@Qualifier("sysmodelDao")
private SysmodelDao dao;;
@RequestMapping(params = "method=test")
public String listBoardTopic(HttpServletRequest request,HttpServletResponse response,ModelMap model) {
System.out.println("have got the login function");
String loginsuccessdir = "/demo/successful.jsp";
String logingfaulsedir = "/demo/noSuccessful.jsp";
String username = request.getParameter("username");
String pwd = request.getParameter("userpassword");
System.out.println("username="+username);
System.out.println("pwd="+pwd);
List ls =dao.find2("");
System.out.println("---------------------");
System.out.println(ls.size());
if(username==null||"".equals(username))
{
return logingfaulsedir ;
}
return loginsuccessdir;
}
}
清单 八Dwr2Controller.java
引用
package com.baoxian.controller;
import org.directwebremoting.annotations.RemoteMethod;
import org.directwebremoting.annotations.RemoteProxy;
import org.springframework.stereotype.Controller;
@Controller
@RemoteProxy(name="Dwr2Controller")
public class Dwr2Controller {
@RemoteMethod
public String getUserName(int id) {
System.out.println("user id is " + id);
return "UserName: " + id;
}
}
清单九 测试页面demo.html:
引用
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>controller_test.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<form action="demo.htm" method='post'>
<input type="hidden" name='method' value='test'>
<table>
<tr><td>用户名:</td><td><input type="text" name="username"/></td></tr>
<tr><td>密码:</td><td><input type="text" name="userpassword"/></td></tr>
<tr><td><input type="submit" value="确定"/></td><td><input type="reset" value="取消"/></td></tr>
</table>
</form>
</body>
</html>
清单十 测试页面webRoot/demo/dwrtest.html:
引用
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>controller_dwr.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type='text/javascript' src='../dwr/util.js'></script>
<script type='text/javascript' src='../dwr/engine.js'></script>
<script type='text/javascript' src='../dwr/interface/Dwr2Controller.js'> </script>
</head>
<script type="text/javascript">
function dwrfn()
{
Dwr2Controller.getUserName("1",callBackHello);
}
function callBackHello(data)
{
alert(data);
}
</script>
<body>
<input type ='button' value="click me to test" onclick="dwrfn()"/>
</body>
</html>
清单十一 测试结果页面webRoot/demo/successful.jsp
引用
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'successful.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
This is successful page. <br>
</body>
</html>
发表评论
-
AESUtils
2018-01-17 14:13 519import java.io.UnsupportedEnc ... -
lbs比较两点坐标
2018-01-16 09:56 0int distance = (int) (S2LatLng. ... -
java ftp上传文件
2017-12-25 10:43 601工具类: import org.apache.c ... -
redis应用方法
2017-11-30 11:47 5621:统计一段时间内,某 ... -
风控系统1
2017-10-12 18:40 649... -
可以保持session的java代码片段
2017-07-12 21:04 661import java.io.File; impor ... -
ubuntu 搭建开发环境
2015-06-16 15:39 0jdk 可以参看其他网站; export JAVA_HO ... -
主线程等待10秒钟,无应答返回(一)
2015-06-05 15:26 2518场景需求: 其他应用向我们的应用A发来请求,如果应用 ... -
drools书籍
2015-03-13 18:23 969附件中有drools书籍 -
一个Tomcat支持不同的域名访问各自不同程序的配置方法
2015-03-11 09:56 563更多信息可以参考网址:http://329937021.i ... -
netty5 包简读
2015-02-13 18:16 0io.netty.bootstrap; 启动器i ... -
netty5 入门翻译
2015-02-12 18:01 866翻译网页网址:http://n ... -
spring-jms
2015-01-12 11:45 722这里写篇文章记录一下jms持久化到mysqlde 使用方 ... -
git 命令大全
2014-11-12 10:03 718git 学习网址http://git-scm.com/bo ... -
groovy eclipse 插件
2014-10-06 16:58 741eclipse version 4.4.0 groovy ... -
docx4j word 工具类及测试类
2014-10-02 22:14 1550import java.io.ByteArrayInputS ... -
docx4j 替换文本
2014-09-29 11:25 1481采用docx4j 替换word模板内容,并输出进行保存 ... -
docx4j 动态生成表格 (一 )
2014-09-28 19:18 1833使用docx4j模板动态制作表格代码实现过程(一 ),模 ... -
java 开发的各种例子
2014-08-13 17:55 648springmvc + springsecurity 实 ... -
tomcat 根项目部署方式
2014-07-08 09:50 591<Host name="admin.yid ...
相关推荐
Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于...
在这个“最全的Spring MVC注解例子”中,我们将深入探讨Spring MVC的核心注解,以及如何实现异步请求处理和错误管理。 1. **Spring MVC核心注解** - `@Controller`:标记一个类为处理HTTP请求的控制器。这是Spring...
Spring MVC 是一个基于Java的轻量级Web应用框架,它为开发者提供了模型-视图-控制器(MVC)架构,使开发人员能够更好地组织和分离应用程序的业务逻辑、数据处理和用户界面。Spring MVC是Spring框架的一个核心组件,...
在Spring MVC框架中,注解的使用极大地简化了配置,提高了开发效率。Spring MVC通过注解可以实现控制器、方法映射、模型数据绑定、视图解析等关键功能。本实例将深入探讨Spring MVC中常见的注解及其应用。 1. `@...
IT学习者Spring MVC注解实例.pdf
首先,Spring MVC注解允许开发者以声明式的方式配置控制器,避免了传统的XML配置文件。这极大地简化了代码,提高了可读性和维护性。例如,`@RequestMapping`注解就是其中的关键,它可以在类级别或方法级别使用,用于...
在“基于注解的Spring MVC环境搭建”中,我们将深入探讨如何利用注解来简化配置,快速建立一个运行中的Web项目。这篇博文(尽管描述为空,但提供了链接)很可能是关于创建一个基本的Spring MVC项目并使用注解来管理...
**基于JPA+Hibernate+Spring+Spring MVC注解方式项目详解** 在现代Java Web开发中,Spring框架扮演了核心角色,而Spring MVC作为其MVC(Model-View-Controller)实现,提供了强大的Web应用程序构建能力。同时,JPA...
总结起来,这个"Spring MVC注解项目实例"涵盖了Spring MVC框架的核心元素,包括注解驱动的控制器、拦截器的使用,以及数据库操作。它为初学者提供了一个动手实践的机会,帮助他们快速掌握Spring MVC的开发技巧。
在本文中,我们将深入探讨Spring MVC中的注解用法,并以文章"spring mvc 注解实现"为例进行说明。 首先,`@Controller` 是Spring MVC中定义控制器的基本注解。当标记在一个类上时,表明该类是一个处理HTTP请求的...
Spring MVC 是一款强大的Java Web开发框架,用于构建高效、可维护和模块化的Web应用程序。它作为Spring框架的一部分,提供了一种优雅的方式来处理HTTP请求和响应,使得开发者可以专注于业务逻辑而不是底层实现。在这...
在这个视频教程中,你可能将学习到如何配置Spring的XML上下文文件以启用注解驱动的配置,如何在Spring MVC中创建注解式的控制器并处理HTTP请求,以及如何通过Hibernate的注解来设计数据模型并执行CRUD操作。...
3. **注解驱动的控制器**:Spring MVC 4.0广泛使用了Java注解,如@Controller、@RequestMapping等,使控制器类的定义更加简洁,减少了XML配置。 4. **路径变量**:在@RequestMapping注解中,可以使用路径变量(path...
Spring MVC 注解式开发使用详解 通过 Spring MVC 注解式开发可以简化开发过程,提高开发效率。下面将详细介绍 Spring MVC 注解式开发的使用方法。 定义处理器 在 Spring MVC 中,处理器是核心组件,负责处理用户...
在这个注解实例中,我们将深入探讨Spring MVC中的核心注解以及如何利用它们实现对数据库表的增删改查(CRUD)操作。拦截器是Spring MVC中的另一个重要概念,它允许我们在请求处理前后执行自定义逻辑。 首先,让我们...
总结,这个压缩包提供了一个完整的Spring MVC和MyBatis整合的示例,包含了数据库脚本和详尽的注释,无论你是初学者还是有经验的开发者,都能从中受益。通过研究源码,你可以掌握Web应用的开发流程,理解Spring MVC和...
在Spring MVC中,开发者可以通过@Autowired注解自动装配依赖,使得代码更易于测试和维护。 此外,Spring MVC还提供了数据绑定和验证功能。表单提交的数据可以直接绑定到控制器方法的参数上,通过@ModelAttribute...
Spring MVC 是一个基于Java的轻量级Web应用框架,它是Spring框架的重要组成部分,主要用于构建Web应用程序的后端控制器。这个教程“Spring MVC - A Tutorial”旨在帮助开发者深入理解和掌握Spring MVC的核心概念和...
在本教程中,我们将深入探讨如何使用Spring MVC、Spring和Hibernate三大框架进行全注解的整合开发。这个视频教程系列的第12部分,将帮助开发者掌握如何在Java Web项目中高效地集成这三个核心框架,实现松耦合、可...