我用的是eclipse3.0.1+tomcat5+lomboz3.0,我写了一个index.jsp和一个servlet:
我在jsp中使submit提交到servlet上去,可是我的页面刚打开就打不开。
不知道是不是配置有问题,代码如下:
jsp如下:
<!-- Copyright (c) 2002 by ObjectLearn. All Rights Reserved. -->
<html>
<head>
<title>FormGetExample</title>
</head>
<body background="#FFFFF">
<form name="form" method="get" action="http://localhost:8080/servlet/FormGetExample1">
<table width="261" height="30">
<tr>
<td width="109" height="10">姓名:</td>
<td width="276" height="10">
<input type="text" name="nickname">
</td>
</tr>
<tr>
<td width="109" height="8">密码:</td>
<td width="276" height="4">
<input type="password" name="pssword1" value="">
</td>
</tr>
</table>
<p align="center">
<input type="submit" name="submit" value="确定">
<input type="submit" name="submit" value="重来">
</p>
</form>
</body>
</html>servlet如下:
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;public class FormGetExample1 extends HttpServlet {
public void doGet(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>Servlet Get Example</TITLE></HEAD>");
out.println(" <BODY>");
out.print("<p> </p>");
out.print("<p><font size='+4'>"+"Servlet Get Example"+"</font></p>");
Enumeration Enumeration = request.getParameterNames();
while(Enumeration.hasMoreElements())
{
String key = (String)Enumeration.nextElement();
String value = request.getParameter(key);
out.print("<P>");
out.print(key+"="+value);
out.print("</P>");
}
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
}
web.xml如下:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Copyright (c) 2002 by ObjectLearn. All Rights Reserved. -->
<web-app>
<servlet>
<servlet-name>FormGetExample1</servlet-name>
<display-name>FormGetExample1</display-name>
<description>FormGetExample1</description>
<servlet-class>FormGetExample1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FormGetExample1</servlet-name>
<url-pattern>FormGetExample1</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> <error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page></web-app>请高手指教,给高分。
我在jsp中使submit提交到servlet上去,可是我的页面刚打开就打不开。
不知道是不是配置有问题,代码如下:
jsp如下:
<!-- Copyright (c) 2002 by ObjectLearn. All Rights Reserved. -->
<html>
<head>
<title>FormGetExample</title>
</head>
<body background="#FFFFF">
<form name="form" method="get" action="http://localhost:8080/servlet/FormGetExample1">
<table width="261" height="30">
<tr>
<td width="109" height="10">姓名:</td>
<td width="276" height="10">
<input type="text" name="nickname">
</td>
</tr>
<tr>
<td width="109" height="8">密码:</td>
<td width="276" height="4">
<input type="password" name="pssword1" value="">
</td>
</tr>
</table>
<p align="center">
<input type="submit" name="submit" value="确定">
<input type="submit" name="submit" value="重来">
</p>
</form>
</body>
</html>servlet如下:
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;public class FormGetExample1 extends HttpServlet {
public void doGet(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>Servlet Get Example</TITLE></HEAD>");
out.println(" <BODY>");
out.print("<p> </p>");
out.print("<p><font size='+4'>"+"Servlet Get Example"+"</font></p>");
Enumeration Enumeration = request.getParameterNames();
while(Enumeration.hasMoreElements())
{
String key = (String)Enumeration.nextElement();
String value = request.getParameter(key);
out.print("<P>");
out.print(key+"="+value);
out.print("</P>");
}
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
}
web.xml如下:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Copyright (c) 2002 by ObjectLearn. All Rights Reserved. -->
<web-app>
<servlet>
<servlet-name>FormGetExample1</servlet-name>
<display-name>FormGetExample1</display-name>
<description>FormGetExample1</description>
<servlet-class>FormGetExample1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FormGetExample1</servlet-name>
<url-pattern>FormGetExample1</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> <error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page></web-app>请高手指教,给高分。
解决方案 »
- ajax前台的输出
- 修改页面后没有变化
- 一个有关sql的简单问题
- 关于在jsp页面中显示异常的问题
- 为什么每次更新主页后页面上的tif图片就显示不出来了
- 如何用java把word或excel以二进制方式存入oracle中,又如何修改些字段,此字段是不是需要blob型的,那位有代码,可否发给我一份,多谢
- jdk1.5不支持tomcat5.0.16吗
- 刚接触JAVA,希望大家能介绍点JAVA方面的好书,谢谢拉!
- PHP调用Java时如果给Java的方法传输对象变量?解决后再送100分!!!
- fullcalendar 另外N条
- jsp 发布 的 怪问题 ~~高分 求救 ~~
- 求一高手帮忙解决一个小问题,可付费。
你项目名是什么??servlet???
http://localhost:8080/项目名/FormGetExample1
HTTP Status 404 - /FormGetExample/FormGetExample--------------------------------------------------------------------------------type Status reportmessage /FormGetExample/FormGetExampledescription The requested resource (/FormGetExample/FormGetExample) is not available.
--------------------------------------------------------------------------------Apache Tomcat/5.0.28
action改为FormGetExampole1也不行。
急急急!!!
action="FormGetExample1"
不行就试试
action="/FormGetExample1"
action="./FormGetExample1"
<input type="reset" name="reset" value="重来">
<servlet-name>FormGetExample1 </servlet-name>
<display-name>FormGetExample1 </display-name>
<description>FormGetExample1 </description>
<servlet-class>这里应该把FormGetExample1所在包名写完整 </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FormGetExample1 </servlet-name>
<url-pattern>这里必须有/FormGetExample1 </url-pattern>
</servlet-mapping>
还有页面FORM中的ACTION="这里应该写配置文件中的<url-pattern>中的地址:/FormGetExample1 "
改为
action="/FormGetExample1"
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception javax.servlet.ServletException: Wrapper cannot find servlet class FormGetExample1 or a class it depends on
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
java.lang.Thread.run(Unknown Source)
root cause java.lang.ClassNotFoundException: FormGetExample1
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1340)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1189)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
java.lang.Thread.run(Unknown Source)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
//这里名字要与mapping的名字对应
<servlet-name>FormGetExample1 </servlet-name>
<display-name>FormGetExample1 </display-name>
<description>FormGetExample1 </description>
//这里是FormGetExample1这个类的路径,也要包括包的名字
<servlet-class>FormGetExample1 </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FormGetExample1 </servlet-name>
这里是JSP页面的引用路径
<url-pattern>/FormGetExample1 </url-pattern>
</servlet-mapping>
action="http://localhost:8080/servlet/FormGetExample1"
改为
action="/FormGetExample1"
这样检查下应该就可以了。
比如
action="../../Test"