myeclipse 第一个程序就不能运行,请各位帮忙指教

Mike的小山 2013-07-11 06:18:12
刚装的myeclipse2013 all-in-one,建立web project工程和程序servlet文档结构如图


程序内容:

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloServlet extends HttpServlet {

/**
* Constructor of the object.
*/
public HelloServlet() {
super();
}

/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}

/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");String requestURI=request.getRequestURI();
out.println("<form action='"+requestURI+"' method='post'>");
out.println("Input your name:<input type='text' name='name'/>");
out.println("<input type='submit'/>");
out.println("</form>");
out.println("");

String name=request.getParameter("name");
if(name!=null && name.trim().length()>0){
out.println("Hello,<b>"+name+"</b>.");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
}

/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the POST method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}

/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}

}

web.xml为自动生成,内容:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
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_3_0.xsd">
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>com.mikedehill.firstweb.HelloServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/servlet/HelloServlet</url-pattern>
</servlet-mapping>

</web-app>

tomcat可以启动
2013-7-11 16:53:57 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:FirstWeb' did not find a matching property.
2013-7-11 16:53:58 org.apache.catalina.core.AprLifecycleListener initializeSSL
信息: OpenSSL successfully initialized (OpenSSL 1.0.1d 5 Feb 2013)
2013-7-11 16:53:59 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-apr-8080"]
2013-7-11 16:53:59 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["ajp-apr-8009"]
2013-7-11 16:53:59 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 3969 ms
2013-7-11 16:53:59 org.apache.catalina.core.StandardService startInternal
信息: Starting service Catalina
2013-7-11 16:53:59 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.40
2013-7-11 16:54:01 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory D:\Program Files\apache-tomcat-7.0.40\webapps\DeployCopy
2013-7-11 16:54:02 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory D:\Program Files\apache-tomcat-7.0.40\webapps\docs
2013-7-11 16:54:02 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory D:\Program Files\apache-tomcat-7.0.40\webapps\examples
2013-7-11 16:54:02 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2013-7-11 16:54:02 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2013-7-11 16:54:02 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache@1a05bdb')
2013-7-11 16:54:02 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory D:\Program Files\apache-tomcat-7.0.40\webapps\host-manager
2013-7-11 16:54:03 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory D:\Program Files\apache-tomcat-7.0.40\webapps\manager
2013-7-11 16:54:03 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory D:\Program Files\apache-tomcat-7.0.40\webapps\ROOT
2013-7-11 16:54:03 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-apr-8080"]
2013-7-11 16:54:03 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-apr-8009"]
2013-7-11 16:54:03 org.apache.catalina.startup.Catalina start
信息: Server startup in 3952 ms

1、按小三角运行按钮显示:the serve is not specified

2、用浏览器键入:http://localhost:8080/FirstWeb/servlet/HelloServlet后回车,显示:
HTTP Status 404 - /FirstWeb/servlet/HelloServlet

--------------------------------------------------------------------------------

type Status report

message /FirstWeb/servlet/HelloServlet

description The requested resource is not available.


--------------------------------------------------------------------------------

Apache Tomcat/7.0.40

请教各位,这个程序应该如何才能编译运行?
...全文
344 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
lkq_david 2013-07-16
  • 打赏
  • 举报
回复
项目没部署好吧,访问你的端口号,看看小猫头能不能出来
Mike的小山 2013-07-16
  • 打赏
  • 举报
回复
引用 17 楼 u011238857 的回复:
1、工具栏windows->showview->servers
2、servers视图,右键选择Add and Remove
3、选择你的项目添加到server
4、点击三角运行





是这样吗,还是不行
风中的木头 2013-07-15
  • 打赏
  • 举报
回复
1、工具栏windows->showview->servers 2、servers视图,右键选择Add and Remove 3、选择你的项目添加到server 4、点击三角运行
Mike的小山 2013-07-15
  • 打赏
  • 举报
回复
引用 15 楼 u011237944 的回复:
[quote=引用 6 楼 Yuan_Rong_Hua 的回复:] 是你项目没部署成功到的原因,你看你tomcat控制台输出信息,自带的root,manage等都都有输出信息,没有你的firstWeb,你重新部署一下,然后点击run as server application
现在知道是tomcat的问题,但具体在哪不知道。myeclipse自带tomcat7(原来不知道),我将程序部署在自带tomcat7上即可访问了。那么为什么我引入的外部tomcat7.x可以在mycelipse中运行,却不能成功部署程序?谁知道?我希望程序在两个tomcat中都能运行。[/quote] 打错了,是为什么。。。
Mike的小山 2013-07-15
  • 打赏
  • 举报
回复
引用 6 楼 Yuan_Rong_Hua 的回复:
是你项目没部署成功到的原因,你看你tomcat控制台输出信息,自带的root,manage等都都有输出信息,没有你的firstWeb,你重新部署一下,然后点击run as server application
现在知道是tomcat的问题,但具体在哪不知道。myeclipse自带tomcat7(原来不知道),我将程序部署在自带tomcat7上即可访问了。那么问什么我引入的外部tomcat7.x可以在mycelipse中运行,却不能成功部署程序?谁知道?我希望程序在两个tomcat中都能运行。
bobo928843007 2013-07-14
  • 打赏
  • 举报
回复
2013的,我用10.6
  • 打赏
  • 举报
回复
没有指定服务器。。。。。。。
magiccxj 2013-07-12
  • 打赏
  • 举报
回复
从tomcat控制台的信息来看,你的项目没有deploy成功~~所以浏览器访问肯定是404。
aa1143170552 2013-07-12
  • 打赏
  • 举报
回复
http://localhost:8080/FirstWeb/servlet/HelloServlet 对类进行访问? 没用过。。。。
proteinboy 2013-07-12
  • 打赏
  • 举报
回复
404是路径问题,tomcat没有找到
  • 打赏
  • 举报
回复
是你项目没部署成功到的原因,你看你tomcat控制台输出信息,自带的root,manage等都都有输出信息,没有你的firstWeb,你重新部署一下,然后点击run as server application
Mike的小山 2013-07-12
  • 打赏
  • 举报
回复
跟版本有关系吗,应该是个简单问题吧,我是刚学习网络编程啊,有没有 明白点的指教啊
效林少爷 2013-07-12
  • 打赏
  • 举报
回复
引用 2 楼 oh_Maxy 的回复:
擦累。。同LS,6.0的飘过。。
顶个
lqg2608205 2013-07-12
  • 打赏
  • 举报
回复
首先要配置好tomcat,其次要将项目部署到tomcat中,然后开启tomcat,最后在浏览器访问!总共四个步骤!至于每一个步骤如何做!我相信只要学了servlet开发的就应该会配置!
linsn007 2013-07-12
  • 打赏
  • 举报
回复
首先,web项目是需要部署到tomcat下的,怎么配置服务器环境怎么部署,百度。 其次,servlet不是java可运行文件,是不能点三角图标来运行的,要部署到tomcat下用url来访问。
terrylmay 2013-07-12
  • 打赏
  • 举报
回复
没什么问题啊..是不是你的web容器用的是myeclipse中的默认的啊..而且那个三角下面不是都能直接点击的..里面会记录你最近运行的项目名称..说不定你运行的是其他项目而不是你现在这个项目呢..你应该在servlet那个类里面直接点右键..然后run as server就ok了..
shengfenglai 2013-07-11
  • 打赏
  • 举报
回复
我用的是 10.0
oh_Maxy 2013-07-11
  • 打赏
  • 举报
回复
擦累。。同LS,6.0的飘过。。
KDJack 2013-07-11
  • 打赏
  • 举报
回复
高科技啊。。。。。我都还在用MyEclipse6.0
MyEclipse2013 (32+64)下载地址(建议使用迅雷下载) http://downloads.myeclipseide.com/downloads/products/eworkbench/2013/installers/myeclipse-pro-2013-offline-installer-windows.exe 安装后先不要启动,先运行破解文件。 破解文件需要JAVA环境支持,先安装JDK,配置环境变量(不会百度之) 破解文件还是之前的,只是帮大家验证了一下重新打包上传分享 破解文件支持9.x~10.7.1的破解 在此鄙视一下网上收费下载的。 MyEclipse 2013 目录结构有点不一样 所以替换教程中的第五步 选择替换目录直接替换安装目录下的\plugins 目录即可 2013 版本 更改了很多东西,至少我自己的许多web项目迁移过去会报错, 因此不太推荐使用以前版本的人升级使用2013版本,当然如果是学习使用倒是没什么 测试两台 win8 x 64 破解MyEclipse2013都是通过的 如果觉得不适应2013 可以继续尝试10.7.1版本 MyEclipse10.7.1 (32+64)下载地址 http://downloads.myeclipseide.com/downloads/products/eworkbench/indigo/installers/myeclipse-10.7.1-offline-installer-windows.exe 特别要注意的是 MyEclipse2013 破解后 支持war包导出了 之前9.x~10.7.1 的所有版本破解之后导出war包都会报错! 免责声明: 本破解程序来自于互联网分享,不得用于商业用途,提供破解仅供学习交流使用,支持购买正版! 因使用本软件造成的法律纠纷与本人无关!

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧