㈠ 关于nlpir在javaweb项目里的初始化问题
用windows搜索功能或者eclipse搜索功能 搜sale_car_list.html 或者 *.html
㈡ 发布webservice,java类初始化问题
发布成webservice后,我发现,不管是调用其中的get,set,方法,构造函数都要被调用一次,而且每次get,set里打印的地址也不一样,怎么能使得set以后,能get到set的字符串呢?谢谢
这说明每次你调用webservice都会实例化一个Test对象
所以你第二次get调用时 也会触发构造方法 也就是说这时候的Test已经是一个新的实体类了和你set的时候不是一个对象了
你的需求用一般的servlet就行了 每次用户通过你开发servlet开远程控制socket服务器
㈢ java web Service类的初始化问题
UserService ue;
改为
UserService ue = new UserService();
㈣ java web转java 怎么初始化web.xml中的对象
不明白你具体需要问什么,web.xml文件是容器去控制的,只在应用启动的或者重新加载的时候容器去读取一次。容器就是指tomcat、jetty等用来部署java应用的程序。如果你要容器去读懂你web.xml中的内容,你就必须根据web.xml的规范,这个规范写在dtd中或者schema中,比如要实例化servlet,就要这么写
<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>包名.类名</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>*.html</url-pattern><!--servlet映射的路径-->
</servlet-mapping>
写到这里,解释起来太困难,建议看官方的文档进行学习!
㈤ 在基于spring搭建的java web应用中,是通过什么方式触发spring的初始化过程的
前段时间在公司做了一个项目,项目用了spring框架实现,WEB容器是Tomct 5,虽然说把项目做完了,但是一直对spring的IoC容器在web容器如何启动和起作用的并不清楚。所以就抽时间看一下spring的源代码,借此了解它的原理。
我们知道,对于使用Spring的web应用,无须手动创建Spring容器,而是通过配置文件,声明式的创建Spring容器。因此在Web应用中创建Spring容器有如下两种方式:
1. 直接在web.xml文件中配置创建Spring容器。
2. 利用第三方MVC框架的扩展点,创建Spring容器。
其实第一种方式是更加常见。为了让Spring容器随Web应用的启动而启动,有如下两种方式:
1. 利用ServletContextListener实现。
2. 利用load-on-startup Servlet实现。
Spring提供ServletContextListener的一个实现类ContextLoaderListener,该类可以作为Listener 使用,它会在创建时自动查找WEB-INF下的applicationContext.xml文件,因此,如果只有一个配置文件,并且文件名为applicationContext.xml,则只需在web.xml文件中增加以下配置片段就可以了。
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
如果有多个配置文件需要载入,则考虑使用<context-param...>元素来确定配置文件的文件名。ContextLoaderListener加载时,会查找名为contentConfigLocation的初始化参数。因此,配置<context-param...>时就指定参数名为contextConfigLocation。
带多个配置文件的web.xml文件如下:
<context-param>
<param-name>contextLoaderListener</param-name>
<param-value>
WEB-INF/*.xml, classpath:spring/*.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
多个配置文件之间用“,”隔开。
下面我们来看它的具体实现过程是怎样的,首先我们从ContextLoaderListener入手,它的代码如下:
public class ContextLoaderListener implements ServletContextListener
{
private ContextLoader contextLoader;
/**
* 这个方法就是用来初始化web application context的
*/
public void contextInitialized(ServletContextEvent event)
{
this.contextLoader = createContextLoader();
this.contextLoader.initWebApplicationContext(event.getServletContext());
}
/**
* 创建一个contextLoader.
* @return the new ContextLoader
*/
protected ContextLoader createContextLoader()
{
return new ContextLoader();
}
................
}
㈥ java web项目初始化问题
那就放进Session里呗
㈦ java web开发 数据库连接池什么时候初始化
数据库连接池处言喻现部application server都提供自数据库连接池案要按照application server文档说明确配置即应用享受数据库连接池处 些候我应用独立java application并普通WEB/J二EE应用且单独运行要application server配合种情况我需要建立自数据库连接池案 一、 DBCP DBCPApache源项目: commons.dbcp DBCP依赖Apache另外二源项目 commons.collectionscommons.pool dbcp包目前版本一.二.一:中国jakarta.apache.org/commons/dbcp/ pool包目前版本一.三:中国jakarta.apache.org/commons/pool/ common-collections包:中国jakarta.apache.org/commons/collections/ 载些包并些包路径添加classpath使用dbcp做项目数据库连接池使用 建立我自数据库连接池使用xml文件传入需要参数使用hard code式简单介绍所需要我自写代码少要建立文件: import org.apache中国mons.dbcp.BasicDataSource; import org.apache中国mons.dbcp.BasicDataSourceFactory; import java.sql.SQLException; import java.sql.Connection; import java.util.Properties; public class ConnectionSource { private static BasicDataSource dataSource = null; public ConnectionSource() { } public static void init() { if (dataSource != null) { try { dataSource.close(); } catch (Exception e) { } dataSource = null; } try { Properties p = new Properties(); p.setProperty("driverClassName", "oracle.jdbc.driver.OracleDriver"); p.setProperty("url", "jdbc:oracle:thin:@一9二.一陆吧.0.一:一5二一:testDB"); p.setProperty("password", "scott"); p.setProperty("username", "tiger"); p.setProperty("maxActive", "三0"); p.setProperty("maxIdle", "一0"); p.setProperty("maxWait", "一000"); p.setProperty("removeAbandoned", "false"); p.setProperty("removeAbandonedTimeout", "一二0"); p.setProperty("testOnBorrow", "true"); p.setProperty("logAbandoned", "true"); dataSource = (BasicDataSource) BasicDataSourceFactory.createDataSource(p); } catch (Exception e) { } } public static synchronized Connection getConnection() throws SQLException { if (dataSource == null) { init(); } Connection conn = null; if (dataSource != null) { conn = dataSource.getConnection(); } return conn; } } 接我应用要简单使用ConnectionSource.getConnection()取连接池数据库连接享受数据库连接带给我处我使用完取数据库连接要简单使用connection.close()连接返连接池至于直接关闭连接返给连接池dbcp使用委派模型实现Connection接口 使用Properties创建BasicDataSource参数设置比较重要: testOnBorrow、testOnReturn、testWhileIdle意思取连接、返连接或连接空闲否进行效性验证(即否数据库连通)默认都false所数据库连接某种原断掉再连接池取连接实际能效连接所确保取连接效 些属性设true进行校验需要另参数:validationQueryoracle说:SELECT COUNT(*) FROM DUAL实际简单SQL语句验证SQL语句数据库跑已连接结返 二参数:timeBetweenEvictionRunsMillis minEvictableIdleTimeMillis 两配合持续更新连接池连接象timeBetweenEvictionRunsMillis 于0每timeBetweenEvictionRunsMillis 间启线程校验连接池闲置间超minEvictableIdleTimeMillis连接象 其些参数参考源代码 二、 C三P0: C三P0放源代码JDBC连接池C三PO 连接池优秀连接池推荐使用C三PO实现JDBC三.0规范部功能性能更加突,包括实现jdbc三jdbc二扩展规范说明Connection Statement 池DataSources 象 载址:中国sourceforge.net/projects/c三p0 package com.systex.utils.web; import java.beans.PropertyVetoException; import java.sql.Connection; import java.sql.SQLException; import javax.sql.DataSource; import com.mchange.v二.c三p0.ComboPooledDataSource; public class C三PODataSource { private static ComboPooledDataSource dataSource = null; private static final String driver = "com.mysql.jdbc.Driver"; private static final String url = "jdbc:mysql://localhost:三三0陆/wyd"; private static final String userName = "root"; private static final String password = "root"; public static DataSource getDataSource() { if (dataSource == null) { dataSource = new ComboPooledDataSource(); try { dataSource.setDriverClass(driver); } catch (PropertyVetoException e) { System.out.println("DataSource Load Driver Exception!!"); e.printStackTrace(); } dataSource.setJdbcUrl(url); dataSource.setUser(userName); dataSource.setPassword(password); // 设置连接池连接容量 dataSource.setMaxPoolSize(二0); // 设置连接池连接容量 dataSource.setMinPoolSize(二); // 设置连接池statements象容量 dataSource.setMaxStatements(一00); } return dataSource; } public static Connection getConnection() throws SQLException { return C三PODataSource.getDataSource().getConnection(); } } 三、 Proxool Java SQL Driver驱程序提供选择其类型驱程序连接池封装非简单移植现存代码完全配置快速熟健壮透明现存JDBC驱程序增加连接池功能 官中国站: 中国proxool.sourceforge.net/ 载址:中国proxool.sourceforge.net/download.htm
㈧ javaweb 普通工具类 如何在web启动初始化时获取web根目录,项目中只有spring框架
使用Spring,就可以用一种比较优雅的方式来获取了。
在web.xml中的<web-app>节点内加入:
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>tansungWeb.root</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.WebAppRootListener</listener-class>
</listener>
然后在普通的Java类中(不是action中),就可以通过System.getProperty("tansungWeb.root")获取了web根目录了。
然后再拼凑路径的时候,最好不要直接使用/或者\,最好使用File.separatorChar
㈨ java web如何 初始化下拉列表
一般不要初始化,即使加载了,如果没有被使用,浪费流量。给 select 添加 onselect 事件,使用Ajax 调用数据库,一般请求过一次后会缓存到本机,很方便的。试试吧