JSP开发问题

zhangfengyi zhangfengyi 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
第一次开发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>
...全文

相关推荐

评论 15
收藏 已收藏
分享
返回顶部
zhangfengyi
Web 开发 81,108 成员 341,721 内容