JSP开发问题
第一次开发JSP程序,按照网上介绍的教程做的表单提交程序,点提交没有反应,不知道是哪里的错,怎样调试,把页面贴出来,帮忙分析一下。
JSP页面:

JSP代码:
TestServlet代码:
web.xml配置
result.jsp页面:
JSP页面:

JSP代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<format action="TestServlet">
w3c在线教程:
<input type="text" name="weburl" size="100"/><br/>
<input type="submit" value="提交"/>
</format>
</body>
</html>
TestServlet代码:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TestServlet extends HttpServlet {
private static final long serialVersionUID=-1575386983723846021L;
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String weburl=request.getParameter("weburl");
System.out.print(weburl);
if(weburl!=null && weburl.equals("http://www.w3csschool.com"))
{
request.setAttribute("weburl", "你输入的是W3C在线教程网");
}
else
{
request.setAttribute("weburl", "你输入的网址在数据库中未有记录");
}
RequestDispatcher dispatcher=request.getRequestDispatcher("result.jsp");
dispatcher.forward(request, response);
}
}
web.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
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">
<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>TestServlet</servlet-name>
<servlet-class>TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/servlet/TestServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
result.jsp页面:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>结果是:</title>
</head>
<body>
<%=request.getAttribute("weburl")%>
</body>
</html>
...全文
相关推荐
解决JSP开发中的各种乱码问题
综上所述,解决JSP开发中的乱码问题涉及多个环节,需要从输入到输出,从服务器到客户端,再到开发工具等多个层面进行细致的配置和检查。同时,理解并掌握不同组件之间的编码转换规则也是解决乱码问题的关键。
jsp开发中遇到的问题及解决方案.rar
以下是针对JSP、Web开发以及J2EE开发的一些关键知识点和常见问题的解决方案:1. **JSP基本语法问题**:JSP页面由HTML、CSS、JavaScript和Java代码混合组成。
Jsp开发遇到的70个问题及解决方法记录
根据提供的文件信息,我们可以总结出一系列与JSP开发相关的知识点,包括常见的问题及其解决方法。以下是对这些知识点的详细解析:### 1.
Tomcat开发JSP和Servlet需要注意的问题.doc
以下是根据提供的文件内容整理的一些重要问题和解决方案:1. **创建Tomcat项目**: - 在Eclipse等集成开发环境中,需要创建一个专门的Tomcat项目。
解决jsp+servlet开发中的中文乱码问题
### 解决JSP+Servlet开发中的中文乱码问题#### 概述在基于JSP(Java Server Pages)和Servlet技术的Java Web应用开发过程中,中文乱码问题一直是困扰开发者的一大难题


Web 开发
