楼主,请详细说明一下,你的类文件是如何放的,应该放到 web-inf/classes的文件下
解决方案 »
- 对于重复用户名的处理?
- 求Struts、Hibernate、Spring框架官方源码下载地址
- 用struts 中的validation,死活不肯验证啊,求助啊,急死了
- 在myeclipse中配置websphere的问题
- 做一个点击排序的功能
- 怎么去查询两个数据库
- 如何使用JUnit 对 Struts的Action 进行测试?
- Struts中<html:form>中包含<logic:iterate>,提交多个checkId问题(表单一次删除多个选项)
- java API document 有卖的吗?下载太大?20M呢
- 有人用javamail做过邮件群发的程序嘛?请进来
- 哪位知道哪里有obe workflow下载的地方
- 一个执行的问题,求助各位高手。
另外地址栏中url注意,尤其是端口。。
%tomcat_home%\webapps\tech-support\index.html
%tomcat_home%\webapps\tech-support\WEB-INF\web.xml
%tomcat_home%\webapps\tech-support\WEB-INF\classes\DbConnection.class
%tomcat_home%\webapps\tech-support\WEB-INF\classes\Sequencer.class
%tomcat_home%\webapps\tech-support\WEB-INF\classes\TechSupportServlet.class下面是web.xml的内容:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2.2.dtd"><web-app>
<servlet>
<servlet-name>TechSupportServlet Learning</servlet-name>
<servlet-class>TechSupportServlet</servlet-class>
</servlet>
</web-app>
请高手帮我看看,谢谢了。
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2.2.dtd"><web-app>
<servlet>
<servlet-name>TechSupportServlet Learning</servlet-name>
<servlet-class>TechSupportServlet</servlet-class>
</servlet>
</web-app>
<servlet-mapping>
<servlet-name>TechSupportServlet</servlet-name>
<url-pattern>/TechSupportServlet</url-pattern> //请注意这里是否设置正确了,
//另外注意Jsp页面中调 //这个servlet时大小写是否一致
</servlet-mapping>
action后面的是<url-pattern>/TechSupportServlet</url-pattern>中的部分,T小写
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2.2.dtd"><web-app>
<servlet>
<servlet-name>tech</servlet-name>
<servlet-class>TechSupportServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>tech</servlet-name>
<url-pattern>/tech</url-pattern>//这是在浏览时的url
</servlet-mapping>
</web-app>
然后在提交时提交到http://localhost:8080/tech
CoolAbu,我在HTML页面中是这样写的:
<FORM ACTION="/tech" METHOD="POST">
可是还是报错:
HTTP Status 404 - /tech--------------------------------------------------------------------------------type Status reportmessage /techdescription The requested resource (/tech) is not available.
--------------------------------------------------------------------------------Apache Tomcat/5.0.19
<HTML>
<HEAD>
<TITLE>XYZ Corporation, IT Department</title>
</HEAD>
<BODY>
<H1>Technical Support Request</H1>
<HR><BR>
<CENTER>
<FORM ACTION="/tech" METHOD="POST">
<TABLE ALIGN="center" WIDTH="100%" CELLSPACING="2" CELLPADDING="2">
<TR>
<TD ALIGN="right">First Name:</TD>
<TD><INPUT TYPE="Text" NAME="firstName" ALIGN="LEFT" SIZE="15"></TD>
<TD ALIGN="right">Last Name:</TD>
<TD><INPUT TYPE="Text" NAME="lastName" ALIGN="LEFT" SIZE="15"></TD>
</TR>
<TR>
<TD ALIGN="right">Email:</TD>
<TD><INPUT TYPE="Text" NAME="email" ALIGN="LEFT" SIZE="25"></TD>
<TD ALIGN="right">Phone:</TD>
<TD><INPUT TYPE="Text" NAME="phone" ALIGN="LEFT" SIZE="15"></TD>
</TR>
<TR>
<TD ALIGN="right">Software:</TD>
<TD>
<SELECT NAME="software" SIZE="1">
<OPTION VALUE="Word">Microsoft Word</OPTION>
<OPTION VALUE="Excel">Microsoft Excel</OPTION>
<OPTION VALUE="Access">Microsoft Access</OPTION>
</SELECT>
</TD>
<TD ALIGN="right">Operating System:</TD>
<TD>
<SELECT NAME="os" size="1">
<OPTION VALUE="95">Windows 95</OPTION>
<OPTION VALUE="98">Windows 98</OPTION>
<OPTION VALUE="NT">Windows NT</OPTION>
</SELECT>
</TD>
</TR>
</TABLE> <BR>Problem Description
<BR>
<TEXTAREA NAME="problem" COLS="50" ROWS="4"></TEXTAREA> <HR><BR> <INPUT TYPE="Submit" NAME="submit" VALUE="Submit Request">
</FORM>
</CENTER>
</BODY>
</HTML>
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2.2.dtd"><web-app>
<servlet>
<servlet-name>tech</servlet-name>
<servlet-class>TechSupportServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>tech</servlet-name>
<url-pattern>/tech</url-pattern>
</servlet-mapping>
</web-app>
例如你的TechSupportServlet.java 里有这样一句
package TechSupportServlet;
。。
那么你的部署应该是这样的:
目录结构:%tomcat_home%\webapps\tech-support\WEB-INF\classes\TechSupportServlet\TechSupportServlet.classweb.xml:<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2.2.dtd"><web-app>
<servlet>
<servlet-name>tech</servlet-name>
<servlet-class>TechSupportServlet.TechSupportServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>tech</servlet-name>
<url-pattern>/tech</url-pattern>
</servlet-mapping>
</web-app>best regards!
<?xml version="1.0" encoding="ISO-8859-1"?>
换成<?xml version="1.0" encoding="UTF-8"?>这样试用一下
其它得不用改
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import oracle.jdbc.driver.*;
import java.sql.*;
import javax.sql.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/public class TechSupportServlet extends HttpServlet {
static final private String CONTENT_TYPE = "text/html; charset=GBK";
//数据库连接参数
String protocol;
String user;
String password;
//初始化数据库连接协议
public void init() throws ServletException {
String driver = getServletConfig().getInitParameter("driver");
protocol = getServletConfig().getInitParameter("protocol");
user = getServletConfig().getInitParameter("user");
password = getServletConfig().getInitParameter("password"); if (driver == null || protocol == null) {
throw new UnavailableException("Driver not specified.");
} try {
Class.forName(driver);
} catch (ClassNotFoundException cnfe) {
throw new UnavailableException("Driver <" + driver
+ "> not found in the classpath.");
}
}
//Process the HTTP Post request
public void doPost(HttpServletRequest req,HttpServletResponse response) throws ServletException, IOException {
//读取用户输入/选择
String firstName = req.getParameter("firstName");
String lastName = req.getParameter("lastName");
String email = req.getParameter("email");
String phone = req.getParameter("phone");
String software = req.getParameter("software");
String os = req.getParameter("os");
String problem = req.getParameter("problem"); //更新数据库
int requestId = 0;
Connection connection = null;
String insertStatementStr =
"INSERT INTO SUPP_REQUESTS VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
try {
//connection = DriverManager.getConnection(protocol);
connection = DbConnection.getConnection(protocol,user,password);
PreparedStatement insertStatement =
connection.prepareStatement(insertStatementStr);
requestId = Sequencer.getNextNumber(protocol,user,password);
insertStatement.setInt(1, requestId);
insertStatement.setString(2, firstName);
insertStatement.setString(3, lastName);
insertStatement.setString(4, email);
insertStatement.setString(5, phone);
insertStatement.setString(6, software);
insertStatement.setString(7, os);
insertStatement.setString(8, problem);
insertStatement.executeUpdate();
} catch (SQLException sqle) {
throw new ServletException("Database error", sqle);
}
finally {
if (connection != null) {
try {
connection.close();
}
catch (SQLException sqle) { }
}
}
//产生应答页面
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<HTML><HEAD><TITLE>");
out.println("Tech Support: Request Confirmation");
out.println("</TITLE></HEAD>");
out.println("<BODY>");
out.println("<H1>Tech Support: Request Confirmation</H1>");
out.println("<P>Thank you for your request. Your request with the following reference number has been received.</P>");
out.println("<P>Request Reference: " + requestId + "</P>");
out.println("<P>Please note this number for future references.</P>");
out.println("<P>Your request will be attended to within 24 hours.</P>");
out.println("<P>Administrator <br>Techsupport team. </P>");
out.println("</BODY></HTML>");
out.close();
}
//Clean up resources
public void destroy() {
}
}
我不同意你的第一点
因为我看了Tomcat5的servlet-examples
里面有一个HelloWorldExample.java
他就是不在任何包内
您的方法,我也尝试了,不行。
下面是主要设置:
index.html:
<FORM ACTION="servlet/TechSupportServlet" METHOD="POST">web.xml(我这是按照Tomcat里面自带实例做的配置):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2.2.dtd"><web-app>
<servlet>
<servlet-name>TechSupportServlet</servlet-name>
<servlet-class>TechSupportServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TechSupportServlet</servlet-name>
<url-pattern>/servlet/TechSupportServlet</url-pattern>
</servlet-mapping>
</web-app>
我不同意你的第一点
因为我看了Tomcat5的servlet-examples
里面有一个HelloWorldExample.java
他就是不在任何包内
===============================================================没关系,这只是多次莫名其妙的失败中获得的。理论上说,你可以把<url-pattern>/servlet/TechSupportServlet</url-pattern>中的/servlet/TechSupportServlet直接敲在IE中如:http://localhost:8080/yourwebapp/servlet/TechSupportServlet
有结果就对了,没有就有问题。然后,还是要把servlet放在包中。
我在IE中敲入:
http://localhost:8080/servlets-examples/servlet/HelloWorldExample
他的就是能够找到呢?
我看了代码,这个servlet也不在任何包里面啊?
不管怎样,今天我就按照你的办法,加到包里面试试看谢谢你
http://www.djtz.net/get.asp?get=9662
首先确定你的serlet是不是放在web-inf/classes目录下
再看看你的web-inf是不是放在工作目录下,我的意思是必须放在工作目录下
比如你的工作目录是d:\jsp 那你就不能放到d:\jsp\serlet下,我用javabean时碰到过这中问题,再试试看,我不敢保证一定没有问题哦!