我是新手,在Tomcat中设置JNDI资源并设置JNDI资源.
我继承了一个servlet应用程序.它通过WebLogic在测试服务器上运行.servlet应用程序以下列方式访问其数据库资源:
ctx = new InitialContext();
ds = (javax.sql.DataSource)ctx.lookup("myDataBaseName");
conn = ds.getConnection();
Run Code Online (Sandbox Code Playgroud)
当我在测试JSP中尝试它时,它不起作用.我明白了
javax.naming.NameNotFoundException: Name myDataBaseName is not bound in this Context
Run Code Online (Sandbox Code Playgroud)
但是,如果我改变测试JSP代码,我就能使测试JSP工作:
ctx = new InitialContext();
Context envContext = (Context)ctx.lookup("java:/comp/env");
ds = (DataSource)envContext.lookup("myDataBaseName");
conn = ds.getConnection();
Run Code Online (Sandbox Code Playgroud)
我在TOMCAT_HOME/conf/context.html中有这个条目(我只是将它用作我的盒子上的开发环境)
<Resource name="myDataBaseName"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@blahblahblah:1521:database3"
username="joeuser"
password="password"
maxActive="20"
maxIdle="30"
maxWait="-1"/>
</Context>
Run Code Online (Sandbox Code Playgroud)
我在TOMCAT_HOME/conf/web.xml中有这个:
<resource-ref>
<res-ref-name>myDataBaseName</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Run Code Online (Sandbox Code Playgroud)
我读了大约10个关于相关问题的stackoverflow页面,但我不熟悉设置JNDI资源来抽象我的问题的解决方案.
如何更改Tomcat 7设置的方式以允许现有的servlet应用程序以"myDatabaseName"的形式访问其数据库?我没有选择改变servlet应用程序中的代码或改变WebLogic在测试服务器上的设置方式.
我需要改变我在我的计算机上设置Tomcat 7副本的方式(对于开发环境),以允许servlet应用程序以本帖子顶部的第一个引用代码块的方式访问其数据库.
Spring 3.1 Tomcat 6.*
我正在制作一个Spring 3.1 webapp,用LDAP进行身份验证.
我使用我编写的JNDI样式的Java程序测试了LDAP凭据(用户名,密码,ldap URL,搜索模式)(引用如下).该程序工作,转储所有用户属性,包括密码,似乎在LDAP服务器上加密.
当我尝试在Spring 3.1中使用相同的凭据登录时,我收到错误消息"Bad Credentials".
我在日志中收到此消息:
DEBUG [org.springframework.security.authentication.ProviderManager:authenticate] (ProviderManager.java:152) - Authentication attempt using org.springframework.security.ldap.authentication.LdapAuthenticationProvider
DEBUG [org.springframework.security.ldap.authentication.AbstractLdapAuthenticationProvider:authenticate] (AbstractLdapAuthenticationProvider.java:51) - Processing authentication request for user: John.A.Smith
DEBUG [org.springframework.security.ldap.authentication.BindAuthenticator:bindWithDn] (BindAuthenticator.java:108) - Attempting to bind as uid=John.A.Smith,ou=People,o=acme.com,o=acme.com
DEBUG [org.springframework.security.ldap.DefaultSpringSecurityContextSource$1:setupEnvironment] (DefaultSpringSecurityContextSource.java:76) - Removing pooling flag for user uid=John.A.Smith,ou=People,o=acme.com,o=acme.com
DEBUG [org.springframework.security.ldap.authentication.BindAuthenticator:handleBindException] (BindAuthenticator.java:152) - Failed to bind as uid=John.A.Smith,ou=People,o=acme.gov: org.springframework.ldap.AuthenticationException: [LDAP: error code 32 - No Such Object]; nested exception is javax.naming.AuthenticationException: [LDAP: error code 32 - No Such Object] …Run Code Online (Sandbox Code Playgroud) 版本:Mars.1发布(4.5.1)
嗨,
我的包管理器视图是工作文件.我的Project Exlorer View只显示此消息:
"工作集的顶级元素,但没有定义工作集"
几个星期前,我做了一套工作.
我周末离开了Eclipse.
当我回来时,我的Eclipse只显示那个工作集.
取消选择该工作集不会恢复默认显示.
所以,我删除了那个工作集,现在Project Explorer为空,除了该错误消息.
有想法该怎么解决这个吗?
我认为可以自动生成持有者类,只有attritutes的类,获取方法和set方法.我知道Eclipse现在是一个事实上的"标准"Java IDE.Eclipse会这样做吗?做其他IDE吗?
我猜测制作专用数据保持类而不是使用HashMaps的唯一原因是以更加可见/更好的方式使用混合数据类型,以及在插入或检索数据时想要对数据执行某些操作的情况.思考?
我是Maven的初学者.我一直在关注Maven By Example这本书.在6.13节中,作者演示了如何通过命令创建包含依赖项的JAR
mvn install assembly assembly
Run Code Online (Sandbox Code Playgroud)
我按照第6章的例子,除了我用单元测试跳过了部分.我回过头来确保我没有跳过一步.但是当我尝试上面的命令时,我得到了这个错误输出:
[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ simple-weather ---
[INFO]
[INFO] <<< maven-assembly-plugin:2.2-beta-5:assembly (default-cli) @ simple-weather <<<
[INFO]
[INFO] --- maven-assembly-plugin:2.2-beta-5:assembly (default-cli) @ simple-weather ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.094s
[INFO] Finished at: Wed Mar 21 15:53:03 EDT 2012
[INFO] Final Memory: 5M/10M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5:assembly (default-cli) on project simple-weather: Error readi
ng assemblies: No assembly descriptors found. -> [Help …Run Code Online (Sandbox Code Playgroud) 我正在将旧的servlet应用程序转换为Spring 3.1.在此过程中,一些URL现在已过时.我们的网络存在一些问题,不会很快得到解决.我的老板不想相信他们的重定向将始终可用.所以,她让我把自己的重定向放到webapp中.
一切都很好,除了如果URL有一个尾部斜杠,Spring 3.1将找不到处理它的Controller类函数.
http://blah.blah.blah/acme/makedonation 被发现,映射和处理
http://blah.blah.blah/acme/makedonation /没有
这是我用来处理遗留URL的控制器类
import org.springframework.stereotype.Controller;
import org.springframework.validation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.apache.log4j.Logger;
@Controller
public class LegacyServletController {
private static final Logger logger = Logger.getLogger(LegacyServletController.class);
// Redirect these legacy screns "home", the login screen via the logout process
@RequestMapping({"makeadonation","contact","complain"})
public String home() {
logger.debug("started...");
return "redirect:logout";
}// end home()
}// end class LegacyServletController
Run Code Online (Sandbox Code Playgroud)
我用Google搜索并找到了这个Stack Overflow 帖子,它提供了一些建议,但我是Spring的新手,并且对它的实现其中的一些建议还不够了解.这个听起来特别适合我的需求:
spring 3.1 RequestMappingHandlerMapping允许您设置"useTrailingSlashMatch"属性.默认情况下,这是真的.我认为将其切换为false会解决您的问题,
有人会给我一个如何做到这一点的基本例子,引用一个有这样一个例子的URL(我没跟谷歌好运)或者指点一个更好的主意吗?
非常感谢史蒂夫
一些大型Java项目可能需要很长时间才能编译.例如,20分钟或更长时间.显然,在这样大小的项目中,你不希望构建失败18分钟,因为缺少分号.
像findbugs或其他工具这样的实用程序是否会为您捕获编译错误而无需花时间进行编译?
提前谢谢你
史蒂夫
我是 Eclipse 新手。是否有可能在 Eclipse 中点击键绑定并找到它所绑定的命令的名称?
例如,按Ctrl+ Shift+R并在列表中出现类似“open-dialog”的内容,告诉我Ctrl+ Shift+R绑定到命令“open-dialog”。
我有一个遗留站点的要求,我无法重新设计屏幕,我不能使用标头无缓存标签,我必须防止用户在他们退出并按下他们的后退按钮后看到缓存的屏幕.
我差不多要解决了(见下面的代码位)
当页面加载时,我使用JQuery AJAX函数调用Web应用程序并查看用户是否仍然登录.如果没有,用户将被重定向到登录屏幕
<html>
<head>
<!-- all the usual header stuff, plus links to the jQuery libaries, first script tag on page below -->
<script language = "javascript">
$.get("/acme/confirm_authentication",function(data){
if( data != "confirmed"){
location.href = "logout";
}
});
</script>
</head>
<body>
blah blah blah
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我不喜欢这个解决方法的一件大事就是,在JQuery函数完成之前,我可以在瞬间完成内容.
有没有办法可以阻止页面加载/渲染,直到JQuery AJAX函数停止?
谢谢
更新:答案:
我修改了下面接受的答案,包括"cache:false"选项.在Firefox和Chrome中,通过后退按钮访问的页面的缓存副本将运行.ajax(),但会使用变量"data"的缓存副本,这会给我一个过时的答案.
$.ajax({
url: "/acme/confirm_authentication",
async:false,
cache: false,
success: function(data) {
if( data != "confirmed"){
location.href = "logout";
}
}
Run Code Online (Sandbox Code Playgroud)
});
我一直在努力翻新一个非常古老的基于Java Servlet的webapp.webapp允许用户上传图像.webapp存储对数据库中图像的路径引用,但将图像上载到它们所在的服务器上的目录.
webapp的数据库已升级到Oracle 11g,我被告知可以处理二进制信息.
所以,我的问题是,哪个更聪明?
继续将图像作为文件存储在服务器上或将图像填充到Oracle 11g数据库中?
非常感谢提前
史蒂夫
java ×4
eclipse ×2
ajax ×1
image ×1
javascript ×1
jndi ×1
jquery ×1
maven ×1
onload-event ×1
oracle ×1
resources ×1
spring ×1
spring-ldap ×1
spring-mvc ×1
tomcat ×1
upload ×1