我的SSH项目之旅(1.基本配置)

2008年07月17日 JAVA 暂无评论

此项目采用spring+hibernate+struts
数据库是mysql     连接方式采用Connection pool

我截取了几个重要步骤的图
首先配置好DB Driver   数据库连接地址:jdbc:mysql://localhost:3306/myssh
我的SSH项目之旅(1.基本配置)
然后依次加入spring hibernate struts的支持
注意一下数据源的的填写
采用 JNDI
DataSource: java:comp/env/jdbc/myssh
我的SSH项目之旅(1.基本配置)

右键项目属性 加入还没加进来的JAR

版本是eclipse3.2.2+myeclipse5.1.1 这个版本会出现这个问题

我的SSH项目之旅(1.基本配置)

SSH主要是配置文件比较复杂 不过都有一个通用的模式,很多东西都是固定不变的,除了eclipse帮我们自动生成一些,其余只要注意一定的写法就可行

一开始把几个重要的配置文件写好


applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<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
我的SSH项目之旅(1.基本配置)

ContextConfigLocation
我的SSH项目之旅(1.基本配置)

Struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

<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"?>
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4"
  <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





我的SSH项目之旅(1.基本配置)

数据源配制

tomcatservlet.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>

0 条留言  访客:0 条  博主:0 条

  1. 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

  2. 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

  3. 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.

  4. 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.

  5. 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.

  6. avatar clicaTottMirl

    Very kindly blog, designer a wonderful gentleman’s gentleman! Desing is cold!

  7. avatar crazy soft

    Great blog, by swain that wrote so often. The main possibility a affairs that writes to-date bumf 🙂

  8. Great blog, by means of swain that wrote so often. The pipe thing that writes to-date information 🙂

给我留言取消回复