Jsp页面中经常写错和容易忘记的东西

时间:2021-12-22 20:59:22

Jsp页面中经常写错和容易忘记的东西

${pageContext.request.contextPath}

代码” ${pageContext.request.contextPath}”的作用是取出部署的应用程序名。
eg

${pageContext.request.contextPath}/user_login.action
在实际浏览器中显示
http://localhost:8080/CrmDemo3/user_login.action

QBC查询的一些Demo

示例代码

public User login(User user) {
DetachedCriteria criteria = DetachedCriteria.forClass(User.class);
criteria.add(Restrictions.eqOrIsNull("user_code", user.getUser_code()));
criteria.add(Restrictions.eqOrIsNull("user_password", user.getUser_password()));
criteria.add(Restrictions.eqOrIsNull("user_state", "1"));
List<User> list = (List<User>) this.getHibernateTemplate().findByCriteria(criteria);
if(list!=null&&list.size()>0){
return list.get(0);
}else{

return null;
}
}

SSH的一些关键性配置

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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
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/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">

<!-- 配置C3P0连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql:///crm1" />
<property name="user" value="root" />
<property name="password" value="123456" />
</bean>

<!-- 配置SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<!-- 先加载连接池 -->
<property name="dataSource" ref="dataSource" />
<!-- 加载方言和可选项 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>

<!-- 引入映射文件 -->
<property name="mappingResources">
<list>
<value>com/fwj/crm/domain/Customer.hbm.xml</value>
<value>com/fwj/crm/domain/User.hbm.xml</value>
</list>
</property>
</bean>

<!-- 先配置平台事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<!-- 开启事务的注解 -->
<tx:annotation-driven transaction-manager="transactionManager" />

<!-- 客户模块设置 -->
<!-- 配置action -->
<bean id="customerAction" class="com.fwj.crm.web.action.CustomerAction"
scope="prototype">
<property name="customerService" ref="customerService" />
</bean>
<bean id="userAction" class="com.fwj.crm.web.action.UserAction"
scope="prototype">
<property name="userService" ref="userService" />
</bean>


<!-- 配置Service -->
<bean id="customerService" class="com.fwj.crm.service.CustomerServiceImpl">
<property name="customerDao" ref="customerDao" />
</bean>

<bean id="userService" class="com.fwj.crm.service.UserServiceImpl">
<property name="userDao" ref="userDao" />
</bean>
<!-- 配置dao -->
<bean id="customerDao" class="com.fwj.crm.dao.CustomerDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="userDao" class="com.fwj.crm.dao.UserDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>

struts.xml文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<!-- 先配置包结构 -->
<package name="crm" extends="struts-default" namespace="/">
<!-- 是由Struts2框架自己来管理Action -->

<!-- 配置客户的Action,如果Action由Spring框架来管理,class标签上只需要编写ID值就OK -->
<action name="customer_*" class="customerAction" method="{1}">

</action>
<action name="user_*" class="userAction" method="{1}">
<result name="regitSuccess" type="redirect">/login.jsp</result>
<result name="loginSuccess" type="redirect">/index.jsp</result>
<result name="none" type="redirect">/login.jsp</result>
<result name="loginOutSuccess" type="redirect">/login.jsp</result>
</action>
</package>
</struts>

log4j.properties文件

### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.err
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### direct messages to file mylog.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=c:mylog.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ###

log4j.rootLogger=info, stdout

Customer.hbm.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.fwj.crm.domain.Customer" table="cst_customer">
<id name="cust_id" column="cust_id">
<generator class="native" />
</id>

<property name="cust_name" column="cust_name" />
<property name="cust_user_id" column="cust_user_id" />
<property name="cust_create_id" column="cust_create_id" />
<property name="cust_source" column="cust_source" />
<property name="cust_industry" column="cust_industry" />
<property name="cust_level" column="cust_level" />
<property name="cust_linkman" column="cust_linkman" />
<property name="cust_phone" column="cust_phone" />
<property name="cust_mobile" column="cust_mobile" />

</class>
</hibernate-mapping>

实例项目

马上上传
http://download.csdn.net/detail/u014527619/9820577