我正在尝试配置Tomcat 7 JDBC领域配置.我完全遵循了本教程:http: //www.avajava.com/tutorials/lessons/how-do-i-use-a-jdbc-realm-with-tomcat-and-mysql.html
我获得了基本身份验证弹出窗口,但即使我输入了正确的凭据,用户也未经过身份验证.我没有收到任何错误消息.
教程指定的Tomcat 5.5,但我使用Tomcat 7.我刚刚换了connectionPasword,并connectionName和动态Web项目的名称.
这是server.xmlJDBC领域配置
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/tomcat_realm"
connectionName="root"
connectionPassword="root"
userTable="tomcat_users"
userNameCol="user_name"
userCredCol="password"
userRoleTable="tomcat_users_roles"
roleNameCol="role_name" />
Run Code Online (Sandbox Code Playgroud)
这是 web.xml
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>test.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
<security-constraint>
<web-resource-collection>
<web-resource-name>Wildcard means whole app requires authentication</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>dude</role-name>
</auth-constraint>
<user-data-constraint>
<!-- transport-guarantee can be CONFIDENTIAL, INTEGRAL, or NONE -->
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
Run Code Online (Sandbox Code Playgroud)
我只能看到,我收到有关安全性的消息:
Security role name dude used in an <auth-constraint> without …Run Code Online (Sandbox Code Playgroud) 我是 JSF 的初学者,当我在 Eclipse 上配置 Primefaces 时,我遇到了异常。我已经完成了以下操作,将primefaces 添加到我现有的JSF 应用程序中。
primefaces-3.5.jar到库中然后我修改了我的xhtml页面,xhtml页面的内容如下
xmlns:p="http://primefaces.prime.com.tr/ui"
然后它显示错误
NLS missing message: CANNOT_FIND_FACELET_TAGLIB
in:
org.eclipse.jst.jsf.core.validation.internal.facelet.messages
Run Code Online (Sandbox Code Playgroud)
这里可以做些什么来解决这个问题?
Eclipse 细节是
Eclipse Java EE IDE for Web Developers.
Version: Kepler Release
Build id: 20130614-0229
Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的问题,我真的无法理解.
我有一个方法,它接受一个字符串,并确定字符串的第一个字符是什么,然后返回它.
public String deterFirstChar(String value){
String keyValue;
char res;
res = value.charAt(0);
keyValue = Character.toString(res);
if (keyValue == "C"){
return keyValue;
} else if (keyValue == "G") {
return keyValue;
}
System.out.println("Error: Wrong keyParam");
return "F";
}
Run Code Online (Sandbox Code Playgroud)
但是,对于一个示例keyValue = C而不是返回,它会跳过if语句并在我确定keyValue为"C"时返回"F".
为什么会这样?
假设我有这些类:
class A {}
class B extends A {}
Run Code Online (Sandbox Code Playgroud)
也
static void call(A a) { System.out.print("A"); }
static void call(B b) { System.out.print("B"); }
public static void main(String[] args) {
A a = new A();
A b = new B();
call(a);
call(b);
}
Run Code Online (Sandbox Code Playgroud)
我得到的输出是:AA
虽然我在期待:AB
我想知道为什么?
我正在研究JPA标准api,我的数据库包含Employee表.我试图找到所有薪水第二高的员工.我能够成功编写JPQL,如下所示.
SELECT e FROM Employee e WHERE e.salary = (SELECT MAX(emp.salary) FROM Employee emp WHERE emp.salary < (SELECT MAX(employee.salary) FROM Employee employee) )
Run Code Online (Sandbox Code Playgroud)
但现在我正在尝试将其转换为标准api并尝试跟随.
CriteriaQuery<Employee> c = cb.createQuery(Employee.class);
Root<Employee> e1 = c.from(Employee.class);
c.select(e1);
Subquery<Number> sq = c.subquery(Number.class);
Root<Employee> e2 = sq.from(Employee.class);
sq.select(cb.max(e2.<Number> get("salary")));
Subquery<Number> sq1 = sq.subquery(Number.class);
Root<Employee> e3 = sq1.from(Employee.class);
sq1.select(cb.max(e3.<Number> get("salary")));
c.where(cb.lessThan(e2.<Number>get("salary"), e3.<Number>get("salary")));// error here
c.where(cb.equal(e1.get("salary"), sq));
Run Code Online (Sandbox Code Playgroud)
我得到参数与lessThan方法不兼容的错误.我不明白如何才能解决这个问题.我的做法是对的吗?
编辑: - 在Mikko回答后更新问题.
上面提供的jpql提供了以下结果,即薪水第二高的员工.
Harish Taware salary 4000000.0
Nilesh Deshmukh salary 4000000.0
Deodatta Chousalkar salary 4000000.0
Deodatta Chousalkar …Run Code Online (Sandbox Code Playgroud) 我ThMapInfratab1-2.exe在C:\Users\Infratab Bangalore\Desktop\Rod目录下有一个文件.我按照以下方式在命令提示符下执行.它工作正常.
C:\Users\Infratab Bangalore\Desktop\Rod>ThMapInfratab1-2.exe TMapInput.txt
Run Code Online (Sandbox Code Playgroud)
我想用Java技术做同样的程序.使用StackOverFlow伙伴,我试过两种方式.
情况1:
用getRuntime().
import java.util.*;
import java.io.*;
public class ExeProcess
{
public static void main(String args[]) throws IOException
{
Runtime rt = Runtime.getRuntime();
File filePath=new File("C:/Users/Infratab Bangalore/Desktop/Rod");
String[] argument1 = {"TMapInput.txt"};
Process proc = rt.exec("ThMapInfratab1-2.exe", argument1, filePath);
}
}
Run Code Online (Sandbox Code Playgroud)
案例2:
运用 ProcessBuilder
import java.io.File;
import java.io.IOException;
public class ProcessBuilderSample {
public static void main(String args[]) throws IOException
{
String executable = "ThMapInfratab1-2.exe";
String argument1 = …Run Code Online (Sandbox Code Playgroud) 在servlet中跟踪会话的不同方法有哪些.是否可以使用隐藏文件?
import java.util.Random;
public class RandomWithArray {
public static void main(String[] args){
Random r = new Random();
int[] num = new int[5]; //same as "= {0,0,0,0,0}
for (int i = 0; i <num.length; i++){
num[i] = r.nextInt(100) + 1;
}
System.out.println(num[i]);
}
}
Run Code Online (Sandbox Code Playgroud)
Eclipse在打印线上告诉我,
Multiple markers at this line
- i cannot be resolved to a variable
- Line breakpoint:RandomWithArray [line: 14] -
main(String[])
Run Code Online (Sandbox Code Playgroud)
究竟我做错了什么?
有没有办法使用数组而不实际将其分配给变量?例如
for (int numb: {1,2,3,4,5,6}){
System.out.println(number);
}
Run Code Online (Sandbox Code Playgroud)
要么
public class TestArrays{
public static void doStuff(double[] doubles){
//doStuff
}
public static void main(String[] args){
doStuff({1,2,3,4,5,6,7});
}
}
Run Code Online (Sandbox Code Playgroud)
因为当我现在尝试它时,我遇到了编译问题,好像编译器没有将实体识别为数组一样.
int number;
int randomNum1= (int)(Math.random() * 12 + 1);
int randomNum2= (int)(Math.random() * 12 + 1);
try{
number = Integer.parseInt(this.txtInput.getText());
}
catch (Exception e){
JOptionPane.showMessageDialog(this, "Please input a integer.", "Error",
JOptionPane.ERROR_MESSAGE);
return;
}
if (number > randomNum1 && number < randomNum2 || number > randomNum2 && number < randomNum1){
lblRand1.setText(Integer.toString(randomNum1));
lblRand2.setText(Integer.toString(randomNum2));
lblOutput.setText("YOU WIN.");
}else
lblRand1.setText(Integer.toString(randomNum1));
lblRand2.setText(Integer.toString(randomNum2));
lblOutput.setText("YOU LOSE.");
Run Code Online (Sandbox Code Playgroud)
为什么它总是显示你输了,即使我的输入是一个必须赢的数字?
String firstanswer = scan.nextLine();
if(firstanswer == answer2)
{
System.out.println("OK lets get started");
}
else
{
System.out.println("That is incorrect, of course you want to play");
}
Run Code Online (Sandbox Code Playgroud)
// answer2设置为"yes",我在上面声明了它