resin3.0.18有关jsessionid的问题

虚拟空间最近升级为resin3.0.18,本站出现只要在url中出现了jsessionid的情况均不能访问,初步估计是虚拟空间的设置可能屏蔽了这种url的访问。

但是,我们使用了struts的标签库,我目前发现无法避免不在url中出现jsessionid(在一次的连续访问中,这种带jsessionid的url出现一次后面的访问就不出现了)。

查了一下,resin中有关session的设置有下面这么一项可能有用,但是,目前网站移回原来的resin2,到时,空间不提供resin2的时候可以一试。

来自http://www.caucho.com/resin-3.0/config/webapp.xtp

By default, both enable-cookies and enable-url-rewriting are true. To force url rewriting, you would create a configuration like:

<web-app id='/'>

  <session-config

   enable-cookies='false'

   enable-url-rewriting='true'/>

</web-app>

这样,如果空间不能执行带jsessionid的url时,我可以试着把enable-cookies='true',而把enable-url-rewriting='false',这样url中就不会出现jsessionid了,程序通过用户的cookie来保持session。只不过要求用户必须开启cookie了。

另外,有关resin服务器的设置中关于session的部分:http://www.caucho.com/resin-3.0/config/resin.xtp


Attribute Meaning default

alternate-session-url-prefix  a prefix to add the session to the beginning of the URL as a path prefix instead of the standard ;jsessionid= suffix. For clients like mobile devices with limited memory, this will allow careful web designers to minimize the page size.  null 

keepalive-max  the maximum number of keepalive connections  512 

keepalive-timeout  the maximum time a connection is maintained in the keepalive state  120s 

alternate-session-url-prefix  <server>

  ...

  <alternate-session-url-prefix>/~J=</alternate-session-url-prefix>

  ...

 

 

[resin]resin 配置与使用(转帖)

[resin]resin 配置与使用(转自:http://blogger.org.cn/blog/more.asp?name=mjm0928&id=13262)

心得体会

mjm0928 发表于 2006-4-7 12:56:07

 1. <http host='localhost' port='80'/>

   host参数指定的是服务器,port指定的是http端口,默认是localhost和8080。

2. <srun host='localhost' port='6802'/> 这个是jsp和java Servlet的引擎配置。

3. 使用Resin开发Java Web项目时,需要建立自己的WebApp。

4. Resin中的应用可以有2种方式发布:

       一是在Resin的目录下发布;

       二是打包成War发布。

5. 在resin.conf中查找<web-app>标签,该标签表示一个web应用

     标签中,id属性表示该应用的Web路径。如<web-app id='/test'>,表示该应用在Web上访问的时候应该用http://hostname/test/来访问。app-dir属性表示该应用的实际路径。如<app-dir>d:\resin\doc\test</app-dir>表示该应用在d:\resin\doc\test目录下面。默认值为根下面的和id同名的目录。Resin可以配置3种error-page:404错误也就是文件找不到错误页;Exception违例页;不能连接java引擎页。他们分别可以这样子设置。

 

    404文件找不到页

    <web-app id='/app1'>

     <error-page error-code='404' location='/file_not_found.jsp'/>

    </web-app>

 

    Exception 违例页

    <web-app id='/foo'>

     <error-page exception-type='java.lang.NullPointerException' location='/nullpointer.jsp'/>

    </web-app>

 

    不能连接到srun Servlet引擎错误页

 

    该页设置和应用无关,属于服务器的设置。

    <http-server>

     <error-page exception-type='connection' location='/missing_file.html'/>

    </http-server>

 

    参见下面的语句:

 

    <classpath id='WEB-INF/classes' source='WEB-INF/src' compile='true'/>

 

    id参数的值表示classpath中编译后的class的存放路径;

      source参数的值表示classpath中java源代码的存放路径;

      compile中的值可能是true或者false,表示是否由Resin的srun自动编译java源代码。

      Classpath的设置一般和javaBean或者Servlet的使用有关。id的值表示javaBean的编译好的包存放的根,source的值表示javaBean的java源代码存放的根。Servlet相同。

6.  Servlet的设置

      <servlet-mapping url-pattern='*.xtp' servlet-name='xtp'/>

    <servlet-mapping url-pattern='*.jsp' servlet-name='jsp'/>

    <servlet-mapping url-pattern='/servlet/*' servlet-name='invoker'/>

    一般就是指定那些需要通过srun的解析。比如在这里,把*.jsp改成*.jss,其他不变,那么只要在访问时遇到*.jss的文件就和原来遇到*.jsp一样处理。通过这个可以指定解析的引擎,如以下的配置:

    <servlet-mapping url-pattern='*.xtp' servlet-name='com.caucho.jsp.XtpServlet'/>

    在Servlet中,也可以指定servlet。如

    <servlet servlet-name='hello' servlet-class='test.HelloWorld'/>

    <servlet-mapping url-pattern='/hello.html' servlet-name='hello'/>

    在servlet-mapping中有个重要的参数case-sensitive 如果在windows上,最好配置成false,忽略大小写,从而和windows的约定一致。

7.  Session的配置

      <session-config>

    <session-max>4096</session-max>

    <session-timeout>30</session-timeout>

    <enable-cookies>true</enable-cookies>

    <enable-url-rewriting>true</enable-url-rewriting>

    <file-store>WEB-INF/sessions</file-store>

    </session-config>

 

    session-max :最大 session数量

    session-timeout :session过期时间,以分钟为单位。

    是否允许cookie :指session是否采用cookies。如果采用cookies,浏览器必须支持session才能使用,发布时建议改成false。enable-url-rewriting和enable-cookies一般配合使用。如果enable-cookies是false,

    enable-url-rewriting应该设成true比较合适。

    file-store :该配置指示服务器是否把session作为文件存放在服务器上。如果把该项注释掉,则在你的web-app目录下的WEB-Inf/sessions目录不保存序列化后的session对象。Session还有jdbc-store配置,对应着把session通过jdbc永久保存在数据库中。其实也就是会话变量的序列化后的保存和重新载入的物理实现。

 

   

    

关于tomcat服务器优化,常遇到的一些简单问题的解决方法(

关于tomcat服务器优化,常遇到的一些简单问题的解决方法 (z)(转自:http://www.21tx.com/dev/2005/01/14/14647.html)

http://dev.21tx.com 2005年01月14日 Blog bon_jovi

每日文章精萃

.Net:解析Visual Basic.NET事件编程 Java:结合Direct Web Remoting使用AJAX

ASP:如何在 dataGrid 上的第一列加上 Che PHP:嵌入式Web视频点播系统实现方法

JSP:在Windows NT 4.0上安装Apache+Servl CGI:Perl程序设计中常用的函数之二

VB:在VB 中调用动态连接库 VC:目录文件查找包装类

配置tomcat的时候,我想禁掉目录列表的访问。结果通过google的搜索找到了一篇不错的文章。除了我想要的,还有一些其他有用的东西。

出处:你的博客网(yourblog.org)

做JSP时,关于tomcat服务器优化,常遇到的一些简单问题的解决方法:

1.如何禁止访问目录列表:

修改tomcat x.x/conf/Web.XML内的一个属性值,就是把true 改为 false

在web.xml里找到以下代码 

<Servlet>

        <servlet-name>default</servlet-name>

        <servlet-class>

          org.apache.catalina.servlets.DefaultServlet

        </servlet-class>

        <init-param>

            <param-name>debug</param-name>

            <param-value>0</param-value>

        </init-param>

        <init-param>

            <param-name>listings</param-name>

            <param-value>true</param-value>

        </init-param>

        <load-on-startup>1</load-on-startup>

    </servlet>

把其中的<init-param>

            <param-name>listings</param-name>

            <param-value>true</param-value>

        </init-param>

改为 <init-param>

            <param-name>listings</param-name>

            <param-value>false</param-value>

     </init-param>

2.如果某文件资源没有找到,服务器要报404错误,

  如果执行的某个JSP文件产生 NullPointException

  会显示一些不想异常提示代码,

  为了让用户看到更更友好的页面

  可在自己的虚拟目录的WEB-INF/web.xml中作如下的设置

<error-page>

  <error-code>404</error-code>

  <location>/notFileFound.jsp</location>

</error-page>

<error-page>

  <exception-type>Java.lang.NullPointerException</exception-type>

  <location>/null.jsp</location>

</error-page>

  同理,你也可以设置抛出其它异常时应该显示的页面!

  另外在jsp页面最上方加上这样一句话,

<%@ page isErrorPage="true" errorPage="error.jsp"%>

    也可以捕捉NullPointerException这种异常,此时转向error.jsp

3.设置session的超时时间 (单位:分钟)

<session-config>

   <session-timeout>30</session-timeout>

</session-config>

4.设置默认欢迎页面(当不输入文件名,只输入目录时起作用)

<welcome-file-list>

   <welcome-file>index.jsp</welcome-file>

   <welcome-file>index.html</welcome-file>

   <welcome-file>index.htm</welcome-file>

</welcome-file-list>

------------------------

配置好的web.xml文件如下:

------------------------

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app

    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

   <display-name>Tomcat Examples</display-name>

    <description>

      Tomcat Example servlets and JSP pages.

   </description>

<!--

会话超时的设置

设置session 的过期时间,单位是分钟;

-->

<session-config>

<session-timeout>10</session-timeout>

</session-config>

<!-- -->

<welcome-file-list>

<welcome-file>index.jsp</welcome-file>

<welcome-file>index.html</welcome-file>

<welcome-file>index.htm</welcome-file>

</welcome-file-list>

<error-page>

<error-code>404</error-code>

<location>/notFileFound.jsp</location>

</error-page>

<error-page>

<error-code>500</error-code>

<location>/common/500.jsp</location>

</error-page>

<!-- 可以对特定的Exception 捕获 -->

<error-page>

<exception-type>java.lang.NullPointerException</exception-type>

<location>/null.jsp</location> </error-page>

<!--

如果某文件资源没有找到,服务器要报404错误,按上述配置则会调用notFileFound.jsp。

如果执行的某个JSP文件产生NullPointException ,则会调用null.jsp

-->

<!--

下面的写法是错误的,少一个 /

<error-page>

<error-code>404</error-code>

<location>filenotfound.jsp</location>

</error-page>

-->

</web-app>

把一个应用设置成http://localhost/就可运行的默

  昨天晚上,从一个学习日记里的朋友那里学到一点如上的知识:

  步骤:

  1、改8080端口为80端口中,80端口是系统的默认WEB端口吧?

  2、把应用的配置文件中的path="/learndiary" 改为 path="",把系统原来的ROOT应用的 path改了或删除这个应用。

  3、这里访问admin应用可以用:http://localhost/admin,访问manager应用可以用:http://localhost/manager/html

  4、上面的知识我只是从这位朋友那里知道了怎么用,并不知道原因。以后再了解。

与猫同乐(Tomcat+Hibernate)

这是一个Hibernate文档中的简单例子,环境是Tomcat+MySql+Hibernate

下载了Tomcat5.0,安装……

下载了Hibernate2,解包……

下载了MySql-nt5.0,安装……

下载数据库驱动mysql-connector-java-3.0.15-ga,解包……

数据库连接池配置:把数据库驱动mysql-connector-java-3.0.15-ga-bin.jar拷贝到%Tomcat%\common\lib下,在%Tomcat%\conf\server.xml里找到<Host>……</Host>,在其间添加

<Context path="/mytest" docBase="mytest" debug="0" reloadable="true" crossContext="true">

<Resource name="jdbc/mysql" auth="Container" type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/mysql">

<parameter>

<name>factory</name>

<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>

</parameter>

<!-- MySQL dB username and password for dB connections -->

<parameter>

<name>username</name>

<value>root</value>

</parameter>

<parameter>

<name>password</name>

<value>root</value>

</parameter>

<parameter>

<name>driverClassName</name>

<value>org.gjt.mm.mysql.Driver</value>

</parameter>

<parameter>

<name>url</name>

<value>jdbc:mysql://localhost:3306/test</value>

</parameter>

<parameter>

<name>maxActive</name>

<value>100</value>

</parameter>

<parameter>

<name>maxIdle</name>

<value>30</value>

</parameter>

<parameter>

<name>maxWait</name>

<value>10000</value>

</parameter>

</ResourceParams>

</Context>

解释:Context里的path是应用程序的路径,就是%tomcat%\webapps下的目录。

然后配置Hibernate:

在%tomcat%\webapps下建一个mytest目录,以及相应的WEB-INF、classes、lib目录,将Hibernate2.jar拷到lib下,将Hibernate解包后的lib目录下需要用到的包也拷过去:

cglib-full-2.0.2.jar

commons-collections-2.1.1.jar

commons-logging-1.0.4.jar

dom4j-1.4.jar

ehcache-0.9.jar

jta.jar

log4j-1.2.8.jar

odmg-3.0.jar

log4j还有一个properties文件要拷到classes目录下

在WEB-INF下的web.xml里添加数据库连接池的设置

<web-app>

<resource-ref>

<description>DB Connection</description>

<res-ref-name>jdbc/mysql</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

<res-auth>Container</res-auth>

</resource-ref>

</web-app>

这用来指明数据库连接池。然后是设置Hibernate使用这个容器管理的连接池来连接数据库:在classes目录下建一个hibernate.cfg.xml,写入

<?xml version='1.0' encoding='utf-8'?>

<!DOCTYPE hibernate-configuration

PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>

<session-factory>

<property name="connection.datasource">java:comp/env/jdbc/mysql</property>

<property name="show_sql">false</property>

<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>

<!-- Mapping files -->

<mapping resource="Cat.hbm.xml"/>

</session-factory>

</hibernate-configuration>

这里可以看到连接的设置,其中dialect是用来指明一个类,来处理数据库数据类型和Java数据类型之间的对照的。<mapping resource="Cat.hbm.xml"/>是映射设置,下面会提到。先看看根据数据库表结构制作的java bean:

数据库结构为:CAT

Column | Type | Modifiers

--------+-----------------------+-----------

cat_id | character(32) | not null

name | character varying(16) | not null

sex | character(1) |

weight | real |

Indexes: cat_pkey primary key btree (cat_id)

对应的java bean源程序:

package net.sf.hibernate.examples.quickstart;

public class Cat {

private String id;

private String name;

private char sex;

private float weight;

public Cat() {

}

public String getId() {

return id;

}

private void setId(String id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public char getSex() {

return sex;

}

public void setSex(char sex) {

this.sex = sex;

}

public float getWeight() {

return weight;

}

public void setWeight(float weight) {

this.weight = weight;

}

}

然后在classes目录下创建一个Cat.cfg.xml来配置PO对象:

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping

PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

<class name="net.sf.hibernate.examples.quickstart.Cat" table="CAT">

<!-- A 32 hex character is our surrogate key. It's automatically

generated by Hibernate with the UUID pattern. -->

<id name="id" type="string" unsaved-value="null" >

<column name="CAT_ID" sql-type="char(32)" not-null="true"/>

<generator class="uuid.hex"/>

</id>

<!-- A cat has to have a name, but it shouldn' be too long. -->

<property name="name">

<column name="NAME" length="16" not-null="true"/>

</property>

<property name="sex"/>

<property name="weight"/>

</class>

</hibernate-mapping>

在这里可以看到java bean类net.sf.hibernate.examples.quickstart.Cat和数据库表CAT的映射关系。

编译好Cat类,放到相应目录下,OK,配置就完成了。下面是在JSP里应用的例子。

首先我们再创建一个类HibernateUtil,用来处理一些诸如取/关Session的功能,这些功能也可以直接写在JSP里:

package net.sf.hibernate.examples.quickstart;

import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;

import net.sf.hibernate.*;

import net.sf.hibernate.cfg.*;

public class HibernateUtil {

private static Log log = LogFactory.getLog(HibernateUtil.class);

private static final SessionFactory sessionFactory;

static {

try {

// Create the SessionFactory

sessionFactory = new Configuration().configure().buildSessionFactory();

} catch (Throwable ex) {

log.error("Initial SessionFactory creation failed.", ex);

throw new ExceptionInInitializerError(ex);

}

}

public static final ThreadLocal session = new ThreadLocal();

public static Session currentSession() throws HibernateException {

Session s = (Session) session.get();

// Open a new Session, if this Thread has none yet

if (s == null) {

s = sessionFactory.openSession();

session.set(s);

}

return s;

}

public static void closeSession() throws HibernateException {

Session s = (Session) session.get();

session.set(null);

if (s != null)

s.close();

}

}

然后是Cat.JSP,很简单

<%@ page language="java" pageEncoding="GB2312" %>

<%@ page import="net.sf.hibernate.Transaction"%>

<%@ page import="net.sf.hibernate.Session"%>

<%@ page import="net.sf.hibernate.cfg.*"%>

<%@ page import="net.sf.hibernate.Query"%>

<%@ page import="net.sf.hibernate.examples.quickstart.HibernateUtil"%>

<%@ page import="net.sf.hibernate.examples.quickstart.Cat"%>

<%@ page import="java.util.*"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en"><html><head><title>Lomboz JSP</title></head><body bgcolor="#FFFFFF">

<%

//添加一只Cat

Session ses = HibernateUtil.currentSession();

Transaction tx= ses.beginTransaction();

Cat princess = new Cat();

princess.setName("ahxu");

princess.setSex('F');

princess.setWeight(7.4f);

ses.save(princess);

tx.commit();

HibernateUtil.closeSession();

//读取库里所有Cat

ses = HibernateUtil.currentSession();

tx= ses.beginTransaction();

Query query = ses.createQuery("select c from Cat as c where c.sex = :sex");

query.setCharacter("sex", 'F');

for (Iterator it = query.iterate(); it.hasNext();) {

Cat cat = (Cat) it.next();

out.println("Female Cat: " + cat.getName() );

}

tx.commit();

HibernateUtil.closeSession();

%>

</body>

</html>