关于简单JavaWeb应用的问题

lcx929320717 lcx929320717 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我目前的状态:
1.创建好了目录结构。
2.已写好login.htm
<html>
<head>
<title>helloapp</title>
</head>
<body>
<form name="loginForm" method="POST" action="dispatcher">
<table>
<tr>
<td><div align="right">User Name:</div></td>
<td><input type = "text" name="username"></td>
</tr>

<tr>
<td><div align="right">Password:</div></td>
<td><input type = "password" name="password"></td>
</tr>

<tr>
<td><input type="submit" name="submit" value="submit"></td>
<td><input type="reset" name="reset" value="reset"></td>
</tr>

</table>
</form>
</body>
</html>
3.已写好hello.jsp
<html>
<head><title>helloapp</title></head>
<body>
<b>Hello:<%=request.getAttribute("USER")%></b>
</body>
</html>
4.已写好DispatcherServlet.class
package mypack;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;


public class DispatcherServlet extends GenericServlet{

private String target = "/hello.jsp";

public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException{
String username = request.getParameter("username");
String password = request.getParameter("password");

request.setAttribute("USER",username);
request.setAttribute("PASSWORD",password);

ServletContext context = getServletContext();
RequestDispatcher dispatcher = context.getRequestDispatcher(target);
dispatcher.forward(request, response);
}
}我目前的状态:
1.创建好了目录结构。
2.已写好login.htm
<html>
<head>
<title>helloapp</title>
</head>
<body>
<form name="loginForm" method="POST" action="dispatcher">
<table>
<tr>
<td><div align="right">User Name:</div></td>
<td><input type = "text" name="username"></td>
</tr>

<tr>
<td><div align="right">Password:</div></td>
<td><input type = "password" name="password"></td>
</tr>

<tr>
<td><input type="submit" name="submit" value="submit"></td>
<td><input type="reset" name="reset" value="reset"></td>
</tr>

</table>
</form>
</body>
</html>
3.已写好hello.jsp
<html>
<head><title>helloapp</title></head>
<body>
<b>Hello:<%=request.getAttribute("USER")%></b>
</body>
</html>
4.已写好DispatcherServlet.class
package mypack;

import javax.servlet.*;
import javax.servlet.http.*; dnfbaibao.com
import java.io.*;
import java.util.*;


public class DispatcherServlet extends GenericServlet{

private String target = "/hello.jsp";

public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException{
String username = request.getParameter("username");
String password = request.getParameter("password");

request.setAttribute("USER",username);
request.setAttribute("PASSWORD",password);

ServletContext context = getServletContext();
RequestDispatcher dispatcher = context.getRequestDispatcher(target);
dispatcher.forward(request, response);
}
}
...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部
lcx929320717
Java 51,407 成员 86,126 内容