<url-pattern>/servlet/*</url-pattern>
改为/*试试!
改为/*试试!
解决方案 »
- 新手求解 一般的javaweb项目用到了哪些框架
- 紧急求助,刚学netbeans+Tomcat用JSP编写Web Application。写了一半实在写不出来了,求助,非常感谢
- 问个问题,关于JAVA TIMER
- 多附件上传
- struts2中web元素中的一些问题
- 小妹妹不才
- JAVA web项目
- webservice客户端调用服务端org.codehaus.xfire.fault.XFireFault: java.lang.NullPointerExce
- 编译好java文件后,http://localhost:8888/servlet/HelloWorld里面还是浏览不出来
- jtest中 利用spring注入不成功
- 返回的rs为空,该如何处理呢?
- 大家快来抢分哦!
http://java:8080/servlet/HelloServlet?Username=name;
tomcat5.0是吧
若是,那么就把路径改为:D:\Tomcat 5.0\webapps\wssgwps\WEB-INF\classes\test\
在D:\Tomcat 5.0\webapps\wssgwps\WEB-INF下的web.xml配置一下你可以配置一下d:\tomcat5.0\conf\server.xml
<Context path="/wssgwps" docBase="wssgwps" debug="0" reloadable="true" crossContext="true" />
好像是不用配,但最好配一下,我的就是这么配的,你不要放在root 下的,好像路径选择上你吃亏呀,哈哈
哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈
<servlet-mapping>
<servlet-name>First</servlet-name>
<url-pattern>/HelloServlet</url-pattern>
</servlet-mapping>
试试
我把一个已经编译好的servlet文件(HelloWorld.class)放到了WEB-INF/classes下
然后如下配置web.xml
-----
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd"><web-app>
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/servlet/helloworld</url-pattern>
</servlet-mapping></web-app>
-------------------
然后浏览:http://localhost:8080/servlet/HelloWorld
错误:
找不到网页
您要查看的网页可能已被删除、名称已被更改,或者暂时不可用。
。
为什么??哪里有错误呀??
从servlet回到jsp代码如下,你修改一下就可以用了:
//页面转向
ServletContext ctx=this.getServletContext();
RequestDispatcher dispatcher=ctx.getRequestDispatcher("/view/ShowData.jsp");
dispatcher.forward(request,reponse);
到处都可以找到建立数据库连结进行查询的语句,大概如下:
//取得查询语句
String sql=querySql.toString();
Connection con=null;
ResultSet rs=null;
Statement statement=null;
try
{
//准备驱动程序
Class.forName("oracle.jdbc.driver.OracleDriver");
//_logger.debug("成功获得数据库驱动程序");
}
catch(Exception e)
{
_logger.error ("驱动程序异常:" + e.getMessage ());
throw new ServletException (e.getMessage ());
}
try
{
//准备连接数据库
String url="jdbc:oracle:thin:@pyds:1521:toptais";
String userName="";
String password="";
con=DriverManager.getConnection(url,userName,password);
/*
InitialContext ctx=new InitialContext();
DataSource ds=(DataSource) ctx.lookup("toptaisds");
con=ds.getConnection();
*/
//_logger.debug("成功连接数据库");
}
catch(Exception e)
{
_logger.error("连接数据库异常:"+e.getMessage());
throw new ServletException(e.getMessage());
}
try
{
//建立查询对象
statement=con.createStatement();
//_logger.debug("成功建立数据库查询对象");
}
catch(Exception e)
{
//_logger.debug("不能建立数据库查询状态对象:"+e.getMessage());
throw new ServletException(e.getMessage());
}
try
{
//执行查询,获得查询结果
rs=statement.executeQuery(sql);
//_logger.debug("成功取得查询结果");
//遍历结果,取出数据
while (rs.next())
{
……
……}
}
catch(Exception e)
{
_logger.error("查询数据库异常:"+e.getMessage());
throw new ServletException(e.getMessage());
}
把他们装到一起不就行了。
改为<url-pattern>/HelloServlet</url-pattern>
尤其是Mailbomb(网络咖啡),qukmei(鬼才)两位大侠讲清了问题的实质,非常感谢你们!