此项目采用 spring+hibernate+struts 数据库是 mysql 连接方式采用 Connection pool
我截取了几个重要步骤的图 首先配置好 DB Driver 数据库连接地址: jdbc:mysql://localhost:3306/myssh 然后依次加入 spring hibernate struts 的支持 注意一下数据源的的填写 采用 JNDI DataSource: java:comp/env/jdbc/myssh 右键项目属性 加入还没加进来的 JAR 包 版本是 eclipse3.2.2+myeclipse5.1.1 这个版本会出现这个问题
然后依次加入 spring hibernate struts 的支持 注意一下数据源的的填写 采用 JNDI DataSource: java:comp/env/jdbc/myssh 右键项目属性 加入还没加进来的 JAR 包 版本是 eclipse3.2.2+myeclipse5.1.1 这个版本会出现这个问题
SSH 主要是配置文件比较复杂 不过都有一个通用的模式,很多东西都是固定不变的,除了 eclipse 帮我们自动生成一些,其余只要注意一定的写法就可行 一开始把几个重要的配置文件写好
SSH 主要是配置文件比较复杂 不过都有一个通用的模式,很多东西都是固定不变的,除了 eclipse 帮我们自动生成一些,其余只要注意一定的写法就可行 一开始把几个重要的配置文件写好
applicationContext.xml
<? xml version = "1.0" encoding = "UTF-8" ?>
< beans >
< bean id = "dataSource"
class = "org.springframework.jndi.JndiObjectFactoryBean" >
< property name = "jndiName" >
< value > java:comp/env/jdbc/myssh </ value >
</ 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 >
<!-- 表示允许自动提交 -->
<prop key="hibernate.connection.autocommit">true</prop>
<!-- 显示 sql 语句 -->
<prop key="hibernate.show_sql">true</prop>
</ props >
</ property >
</bean>
加入 hibernate 模板支持 <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory"/></property>
</bean>
</ beans > Web.xml
<? xml version = "1.0" encoding = "UTF-8" ?>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/applicationContext.xml
</param-value>
</context-param>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
< servlet >
< servlet-name > action </ servlet-name >
< servlet-class >
org.apache.struts.action.ActionServlet
</ servlet-class >
< init-param >
< param-name > config </ param-name >
< param-value > /WEB-INF/struts-config.xml </ param-value >
</ init-param >
< init-param >
< param-name > debug </ param-name >
< param-value > 3 </ param-value >
<
font face="courier"></init-param >
< init-param >
< param-name > detail </ param-name >
< param-value > 3 </ param-value >
</ init-param >
< load-on-startup > 0 </ load-on-startup >
</ servlet >
< servlet-mapping >
< servlet-name > action </ servlet-name >
< url-pattern > *.do </ url-pattern >
</ servlet-mapping >
</ web-app >
在添加 struts 插件支持 ContextLoaderPlugIn
ContextConfigLocation Struts-config.xml
Struts-config.xml
<? xml version = "1.0" encoding = "UTF-8" ?>
< struts-config >
< data-sources />
< form-beans />
< global-exceptions />
< global-forwards />
< action-mappings />
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor">
</controller>
< message-resources
parameter = "dj.fantlam.myssh.struts.ApplicationResources" />
和spring进行整合,这是struts添加外插件的方法
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> <set-property property="contextConfigLocation" value="/WEB-INF/classes/applicationContext.xml" /> </plug-in> </ struts-config >
编写过滤器进行乱码处理
EncodingFilter.java
package dj.fantlam.myssh.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class EncodingFilter implements Filter {
private String charset = null;
public void destroy() {
// TODO Auto-generated method stub
}
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
// TODO Auto-generated method stub
arg0.setCharacterEncoding(this .charset);
arg2.doFilter(arg0, arg1);
}
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
this .charset=arg0.getInitParameter("charset");
}
}
Web.xml
<? xml version = "1.0" encoding = "UTF-8" ?>
< context-param >
< param-name > contextConfigLocation </ param-name >
< param-value >
/WEB-INF/classes/applicationContext.xml
</ param-value >
</ context-param >
这个是最经典的字符过滤方法了
<filter>
<filter-name>encoding</filter-name>
<filter-class>
dj.fant
lam.myssh.filter.EncodingFilter
</filter-class>
<init-param>
<param-name>charset</param-name>
<param-value>gbk</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
< servlet >
< servlet-name > context </ servlet-name >
< servlet-class >
org.springframework.web.context.ContextLoaderServlet
</ servlet-class >
< load-on-startup > 1 </ load-on-startup >
</ servlet >
< servlet >
< servlet-name > action </ servlet-name >
< servlet-class >
org.apache.struts.action.ActionServlet
</ servlet-class >
< init-param >
< param-name > config </ param-name >
< param-value > /WEB-INF/struts-config.xml </ param-value >
</ init-param >
< init-param >
< param-name > debug </ param-name >
< param-value > 3 </ param-value >
</ init-param >
< init-param >
< param-name > detail </ param-name >
< param-value > 3 </ param-value >
</ init-param >
< load-on-startup > 0 </ load-on-startup >
</ servlet >
< servlet-mapping >
< servlet-name > action </ servlet-name >
< url-pattern > *.do </ url-pattern >
</ servlet-mapping >
</ web-app >
MD5 加密 加入 MD5 支持,为了数据安全,因为不加一旦被黑,所有数据都被看到 不可逆向,为程序的安全性作保障 验证码 image.jsp 防止灌水 使用模板 temp.jsp 拷贝它做新的 JSP 页面 temp.html 做新的 HTML 页面 文件存放目录 分页 split_page.jsp 数据源配制 在 tomcat 的 servlet.xml 文件加入 <Context path="/myssh" docBase="E:JAVASSHworkspaceMySSHWebRoot" debug="5" reloadable="true" crossContext="true"> <Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_MysqlTest_log." suffix=".txt" timestamp="true"/> <Resource name="jdbc/myssh" auth="Container" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/myssh"> <parameter> <name>factory</name> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> </parameter> <parameter> <name>maxActive</name> <value>100</value> </parameter> <parameter> <name>maxIdle</name> <value>30</value> </parameter> <parameter> <name>maxWait</name> <value>5000</value> </parameter> <parameter> <name>username</name> <value>root</value> </parameter> <parameter> <name>password</name> <value>123456</value> </parameter> <parameter> <name>driverClassName</name> <value>org.gjt.mm.mysql.Driver</value> </parameter> <parameter> <name>url</name> <value>jdbc:mysql://localhost:3306/myssh</value>
数据源配制 在 tomcat 的 servlet.xml 文件加入 <Context path="/myssh" docBase="E:JAVASSHworkspaceMySSHWebRoot" debug="5" reloadable="true" crossContext="true"> <Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_MysqlTest_log." suffix=".txt" timestamp="true"/> <Resource name="jdbc/myssh" auth="Container" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/myssh"> <parameter> <name>factory</name> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> </parameter> <parameter> <name>maxActive</name> <value>100</value> </parameter> <parameter> <name>maxIdle</name> <value>30</value> </parameter> <parameter> <name>maxWait</name> <value>5000</value> </parameter> <parameter> <name>username</name> <value>root</value> </parameter> <parameter> <name>password</name> <value>123456</value> </parameter> <parameter> <name>driverClassName</name> <value>org.gjt.mm.mysql.Driver</value> </parameter> <parameter> <name>url</name> <value>jdbc:mysql://localhost:3306/myssh</value> </parameter> </ResourceParams> </Context> </Host> </Engine> </Service> </Server>
I recently decided to make a simple movie about this, I would be honored if you would maybe take a minute to check it and perhaps leave a message about what you think, I left the video url in the “website” field, hopefully you can access it, I appreciate it greatly
Made a video about this, would you and anyone else here mind checking it out real quick and let me know your thoughts? I left the link in the website field, hopefully you can access it. I’d appreciate it greatly, thank you
Nice to be here, I am now in Kuala Lumpur. I got a call this morning to attend a final interview this coming Thursday for an ESL teachng job. This will be a first actual interview since graduation. Do wish me a fruitful attempt. And by the way, Have you stumbled upon any website that is similar to this writing courses teaching site. I am not paying for anything, appreciate if you let me have more information on any such free resource. Cheers.
I can really see your excitement in the work you write. The world can perform with more passionate authors like you that are not scared to say that they feel. Usually go after your own heart.
Nice to be here… I’d like to be to the point. I am trying to build backlinks to my English essays free-for-all website and I would be glad if you can accept my comment here. My resource is a 100 percent free website that helps learners on the essentials of writing compositions and I am without doubt that ESL students will reap some benefits from it. Once more, I hope you will agreed to my posting, and I thank you in advance.
Very kindly blog, designer a wonderful gentleman’s gentleman! Desing is cold!
Great blog, by swain that wrote so often. The main possibility a affairs that writes to-date bumf 🙂
Great blog, by means of swain that wrote so often. The pipe thing that writes to-date information 🙂