我对servlet映射的web.xml结构感到困惑,执行它没有任何问题,但我试图弄清楚为什么我们在部署描述符中有这样的模式.
<web-app>
<servlet>
<servlet-name>Servlet1</servlet-name>
<servlet-path>foo.Servlet</servlet-path>
</servlet>
<servlet-mapping>
<servlet-name>Servlet1</servlet-name>
<url-pattern>/enroll</url-pattern>
</servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)
现在只要我理解url-pattern"/ enroll"的请求,servlet容器就会将servlet-name与url-pattern匹配,并尝试查找相应的servlet-path并转发控件to foo.Servlet.所以基本上会有两个传递一个用于查找servlet-name而另一个用于servlet-path,我的问题是如果容器设计为以下列方式工作
<web-app>
<servlet>
<servlet-name>foo.Servlet</servlet-path>
<url-pattern>/enroll</url-pattern>
</servlet>
</web-app>
Run Code Online (Sandbox Code Playgroud)
如果我们使用以下方法会有什么缺点.这不会更有效,响应时间也会很快.
有没有办法动态地读取和打印对象属性(Java)?例如,如果我有以下对象
public class A{
int age ;
String name;
float income;
}
public class B{
int age;
String name;
}
public class mainA{
A obj1 = new A();
method(A);
method(B);
}
the output should be like
While running method(A):
Attribute of Object are age,name,income;
While executing method(B):
Attribute of Objects are age,name;
Run Code Online (Sandbox Code Playgroud)
我的问题是我可以在method()中传递各种对象,是否有任何方法可以访问不同对象的属性.
我正在尝试运行以下程序:
package jndi;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
public class LDAPRead {
public static void main(String[] args) {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=jaydeetechnology");
try{
System.out.println("creating initial directory context");
DirContext ctx = (DirContext) new InitialContext(env);
System.out.println("search for john hunt");
Attributes attrs = ctx.getAttributes("cn=John Hunt , ou=JayDeeTechnology");
System.out.println("find the surname and print it");
System.out.println("sn: "+attrs.get("sn").get());
ctx.close();
}catch(NamingException e){
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我得到'拒绝连接'错误.如果我错过了什么,请帮助我吗?
creating initial directory context
javax.naming.CommunicationException: localhost:389 [Root exception …Run Code Online (Sandbox Code Playgroud) 我在从数据库中获取结果后在运行时创建一个表.我的应用程序流程是这样的.
JScrollPane tableScroll = new JScrollPane();码:
private void setResultTable(Vector documents, Vector header) {
TableModel model = new DefaultTableModel(documents, header);
documentTable.setModel(model);
tableScroll.add(documentTable);
tableScroll.repaint();
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,在调用setResultTable后,结果没有出现在表中.请帮帮我.提前致谢 !!!
我有以下程序,我在其中添加少量数字来设置和列表然后删除它们,有人可以解释为什么Set和list有不同的行为.
public class SetList {
public static void main(String[] args){
Set<Integer> set = new TreeSet<Integer>();
List<Integer> list = new ArrayList<Integer>();
for(int i=-3;i<3;i++){
set.add(i);
list.add(i);
}
for(int i=0;i<3;i++){
set.remove(i);
list.remove(i);
}
System.out.println(set+" "+list);
}
Run Code Online (Sandbox Code Playgroud)
}
和输出是
[-3, -2, -1] [-2, 0, 2]
Run Code Online (Sandbox Code Playgroud)
我能够理解Set的行为但无法理解List输出的行为.所有帮助真的很感激.
我正在使用DOM生成xml文件,并且程序正常工作并生成文件和输出,但格式如果xml文件不是我所期望的.
这是程序:
package com.mkyong.core;
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
public class WriteXMLFile {
public static void main(String argv[]) {
try {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
// root elements
Document doc = docBuilder.newDocument();
Element rootElement = doc.createElement("company");
doc.appendChild(rootElement);
// staff elements
Element staff = doc.createElement("Staff");
rootElement.appendChild(staff);
// set attribute to staff element
Attr attr = doc.createAttribute("id");
attr.setValue("1");
staff.setAttributeNode(attr); …Run Code Online (Sandbox Code Playgroud) 我是javascript的新手,并尝试执行以下代码,任何人都可以告诉我为什么只有第一个document.write正在执行而不是其他的.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>my first java script</title>
</head>
<body>
<script type="text/javascript">
var myhello="hello world, welcome to java script";
var heading="a page of java script";
var linktag="<a href=\"http://www.google.com\">wanna search on google</a>";
var redtext="<span style=\"color:red\">I am so colorful today!</span>";
var begineffect="<strong>";
var endeffect="</strong>";
var beginpara="<p>";
var endpara="</p>";
document.write(begineffect+heading+endeffect);
document.write(begingpara);
document.write(hello);
document.write(endpara);
document.write(begingpara);
document.write(linktag);
document.write(endpara);
document.write(beginpara);
document.write(redtext);
document.write(endpara);
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我在所有Web浏览器中测试了以下代码.