1、 将servlet-api.jar拷贝到JRE中的JRE_PATH/LIB/EXT目录下。
2、将servlet-api.jar包括路径添加到系统变量CLASSPATH中,忘了这步了 呵呵
tomcat启动的时候报错 配置文件一点都没有变动
2009-5-7 10:37:49 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
信息: The Apache Tomcat Native library which allows optimal performance in produ
ction environments was not found on the java.library.path: C:\Program Files\java
\jdk1.6.0_07\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;.;C:\P
rogram Files\java\jdk1.6.0_07\bin;C:\Program Files\Common Files\Adobe\AGL;C:\Pro
gram Files\StormII\Codec;C:\Program Files\StormII
2009-5-7 10:37:49 org.apache.coyote.http11.Http11BaseProtocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2009-5-7 10:37:49 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 532 ms
2009-5-7 10:37:49 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2009-5-7 10:37:49 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/5.5.27
2009-5-7 10:37:49 org.apache.catalina.core.StandardHost start
信息: XML validation disabled
2009-5-7 10:37:50 org.apache.tomcat.util.digester.Digester endElement
严重: End event threw exception
java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tomcat.util.IntrospectionUtils.callMethodN(IntrospectionUt
ils.java:930)
at org.apache.tomcat.util.digester.CallMethodRule.end(CallMethodRule.jav
a:579)
at org.apache.tomcat.util.digester.Rule.end(Rule.java:229)
at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:105
8)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endEleme
nt(AbstractSAXParser.java:601)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
l.scanEndElement(XMLDocumentFragmentScannerImpl.java:1774)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
l$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2930)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(X
MLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
l.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(X
ML11Configuration.java:807)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(X
ML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.
java:107)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Ab
stractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.p
arse(SAXParserImpl.java:522)
at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1562)
at org.apache.catalina.startup.ContextConfig.applicationWebConfig(Contex
tConfig.java:348)
at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:10
48)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfi
g.java:261)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl
eSupport.java:120)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4
148)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase
.java:760)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:74
0)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.jav
a:927)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.j
ava:890)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492
)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1150)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java
:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl
eSupport.java:120)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443
)
at org.apache.catalina.core.StandardService.start(StandardService.java:4
48)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:700
)
at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
Caused by: java.lang.IllegalArgumentException: Invalid <url-pattern> lookHello i
n servlet mapping
at org.apache.catalina.core.StandardContext.addServletMapping(StandardCo
ntext.java:2327)
at org.apache.catalina.core.StandardContext.addServletMapping(StandardCo
ntext.java:2303)
... 45 more
2009-5-7 10:37:50 org.apache.catalina.startup.ContextConfig applicationWebConfig
严重: Parse error in application web.xml file at jndi:/localhost/ch7/WEB-INF/web
.xml
java.lang.IllegalArgumentException: Invalid <url-pattern> lookHello in servlet m
apping
at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.
java:2726)
at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.
java:2752)
at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:106
1)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endEleme
nt(AbstractSAXParser.java:601)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
l.scanEndElement(XMLDocumentFragmentScannerImpl.java:1774)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
l$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2930)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(X
MLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
l.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(X
ML11Configuration.java:807)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(X
ML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.
java:107)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Ab
stractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.p
arse(SAXParserImpl.java:522)
at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1562)
at org.apache.catalina.startup.ContextConfig.applicationWebConfig(Contex
tConfig.java:348)
at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:10
48)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfi
g.java:261)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl
eSupport.java:120)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4
148)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase
.java:760)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:74
0)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.jav
a:927)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.j
ava:890)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492
)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1150)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java
:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl
eSupport.java:120)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443
)
at org.apache.catalina.core.StandardService.start(StandardService.java:4
48)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:700
)
at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
2009-5-7 10:37:50 org.apache.catalina.startup.ContextConfig applicationWebConfig
严重: Occurred at line 10 column 19
2009-5-7 10:37:50 org.apache.catalina.startup.ContextConfig start
严重: Marking this application unavailable due to previous error(s)
2009-5-7 10:37:50 org.apache.catalina.core.StandardContext start
严重: Error getConfigured
2009-5-7 10:37:50 org.apache.catalina.core.StandardContext start
严重: Context [/ch7] startup failed due to previous errors
2009-5-7 10:37:50 org.apache.coyote.http11.Http11BaseProtocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2009-5-7 10:37:50 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2009-5-7 10:37:50 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/15 config=null
2009-5-7 10:37:50 org.apache.catalina.storeconfig.StoreLoader load
信息: Find registry server-registry.xml at classpath resource
2009-5-7 10:37:50 org.apache.catalina.startup.Catalina start
信息: Server startup in 1125 ms
最近跟着尚学堂的视频做一个在线聊天系统
代码没错 可一run就出错
找不出错哪儿了
import java.io.IOException;
import java.net.*;
public class f {
public static void main(String[] args) {
try {
ServerSocket ss = new ServerSocket (8888);
while(true) {
Socket s = ss.accept();
System.out.println("a client connected!");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
下面是报的错
java.net.BindException: Address already in use: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
at java.net.ServerSocket.bind(ServerSocket.java:319)
at java.net.ServerSocket.<init>(ServerSocket.java:185)
at java.net.ServerSocket.<init>(ServerSocket.java:97)
at ChatServer.main(ChatServer.java:8)
编译时没错 运行时错误就报啦
其一:
public class Fib1{
public static void main(String []args){
System.out.println(f(7));
}
public static long f(int index){
if(index == 1 || index == 2){
return 1;
}
long f1= 1L;
long f2 = 1L;
long f = 0;
for(int i=0;i<index-2;i++){
f = f1+f2;
f1 = f2;
f2 = f;
}
return f;
}
}
其二:
//package demo;
//打印斐波那契数列
public class Fib{
public static void main(String[] args){
int x = 0;
int y = 1;
System.out.print(x+" ");
for(int i=1;i<=20;i++){
System.out.print(y+" ");
y=x+y;
x=y-x;
}
}
}
其三:
//求出第n个数是几
public class Fib{
public static void main(String args[]){
System.out.println(f(6));
}
public static int f(int n){
if(n == 1 || n == 2){
return 1;
}else{
return f(n-1) + f(n-2);
}
}
}
/*
* LoginJDialog.java
*
* Created on 2009年4月17日, 下午2:35
*/
package mydb;
import javax.swing.*;
import java.sql.*;
/**
*
* @author soft
*/
class LoginJDialog extends javax.swing.JDialog {
/** Creates new form LoginJDialog */
private Connection cn;
public Connection getCn() {
return cn;
}
private void quit() {
int tag = JOptionPane.showConfirmDialog(null, "您确定退出程序吗?", "信息", JOptionPane.YES_NO_OPTION);
if(tag==JOptionPane.YES_OPTION){
System.exit(1);
}
}
private void getdata() {
String uid = jTextField1.getText();
String pwd = jPasswordField1.getText();
int tag = 0;
try{
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e){
tag = 1;
}
try{
cn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mytestdb",uid,pwd);
}
catch(SQLException e){
tag = 1;
}
if(tag == 0) setVisible(false);
else JOptionPane.showMessageDialog(this,"数据库错误!","错误",1);
}
public LoginJDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jPasswordField1 = new javax.swing.JPasswordField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
jLabel1.setText("User:");
jLabel2.setText("password:");
jButton1.setText("Cancel");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Confirm");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(34, 34, 34)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addGap(16, 16, 16)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPasswordField1, 0, 0, Short.MAX_VALUE)
.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 126, Short.MAX_VALUE)
.addComponent(jButton2)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(29, 29, 29)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 51, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap())
);
pack();
}// </editor-fold>
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO 将在此处添加您的处理代码:
getdata();
}
private void formWindowClosing(java.awt.event.WindowEvent evt) {
// TODO 将在此处添加您的处理代码:
quit();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO 将在此处添加您的处理代码:
quit();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new LoginJDialog(new javax.swing.JFrame(), true).setVisible(true);
}
});
}
// 变量声明 - 不进行修改
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JTextField jTextField1;
// 变量声明结束
}