这个是welcome.html放在root(tomcat6.0)目录下
<html>
<head><title>Welcome you!<title></head>
<body>
<form action="welcome" method="get">
请输入姓名<input type="text" name="user">
<input type="submit" value="提交">
</form>
</body>
</html>
下面是写的servlet WelcomeYou.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
public class WelcomeYou extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse resp)throws IOException
{
String user=req.getParameter("user");
String welcomeInfo="welcome you "+user;
resp.setContentType("text/html");
PrintWriter out=resp.getWriter();
out.println("<html><head><title>");
out.println("Welcome Page");
out.println("<title><head>");
out.println("<body>");
out.println(welcomeInfo);
out.println("<body><html>");
out.close();
}
}
编译后的class文件放在了root目录下的WEB-INF目录下的classes目录下
WEB-INF的下的web.xml我配置如下
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--><web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5"> <display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<servlet>
<servlet-name>welcome</servlet-name>
<servlet-class>WelcomeYou</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>welcome</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>
</web-app>
为什么在浏览器中输入http://localhost:8080/welcome.html
或者输入http://localhost:8080/welcome 都是一片空白 什么都不显示呢???
<html>
<head><title>Welcome you!<title></head>
<body>
<form action="welcome" method="get">
请输入姓名<input type="text" name="user">
<input type="submit" value="提交">
</form>
</body>
</html>
下面是写的servlet WelcomeYou.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
public class WelcomeYou extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse resp)throws IOException
{
String user=req.getParameter("user");
String welcomeInfo="welcome you "+user;
resp.setContentType("text/html");
PrintWriter out=resp.getWriter();
out.println("<html><head><title>");
out.println("Welcome Page");
out.println("<title><head>");
out.println("<body>");
out.println(welcomeInfo);
out.println("<body><html>");
out.close();
}
}
编译后的class文件放在了root目录下的WEB-INF目录下的classes目录下
WEB-INF的下的web.xml我配置如下
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--><web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5"> <display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<servlet>
<servlet-name>welcome</servlet-name>
<servlet-class>WelcomeYou</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>welcome</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>
</web-app>
为什么在浏览器中输入http://localhost:8080/welcome.html
或者输入http://localhost:8080/welcome 都是一片空白 什么都不显示呢???
解决方案 »
- jsp页面select的值取到action里???怎么为空呢???
- hibernate映射类有boolean类型的属性,更新mysql对应字段(bit类型)后,此字段还是以前的值,求解!
- 我模糊查询的判断语句问题,帮忙看下
- 3个和正则有关(字符串处理)的小问题
- 急!!数据库连接问题
- 树型结构中传值问题 急!!!
- 问个参数传递问题
- JSP使用javabean出错:package dbbean does not exist 或者cannot resolve symbol
- 为什么传到Bean里面的中文这么难搞定呀?
- 急!!大家进来看看。
- 关于.ocx文件
- 页面里嵌入iframe的登陆界面,如何在登陆成功后跳转到到另一页
能访问http://localhost:8080吗?
<Context docBase="c:\tomcat\webapp\app" path="/" reloadable="true"/>