很简单啊 通过jsp 提交参数到servlet 通过判断servlet再值到 jsp 怎么你不会还是刚学?要不联系我看你csdn短信
解决方案 »
- 在session 中销毁对象
- 询问一个Struts 关于Jsp 发送对象给 Action的问题
- FireFox中用iframe无刷新文件上传后回掉js方法的问题
- 请问如何得到分页查询的全部结果集?????
- socket问题
- 怎么用JSP或者JAVA来打印HTML文件(不是HTML页面)?
- struct的js调用,css调用问题?请教各位大侠
- 关于System.in.read();请进来看看!
- 讨论,在Weblogic上运行servlet真的这么麻烦吗?
- 哪位高人会正则表达式啊,想提取字符串中@ @之间的内容
- 急急急急急急急 SQL Server2000 text 数据类型???请高手帮忙!
- 也问一个有关applet不显示的问题
在表单的action提交到你的servlet
在servlet中验证AA是否等于123
然后返回到JSP
从request.getAttribute中取得一个String并显示。
package untitled11;import javax.servlet.*;
import javax.servlet.http.*;import java.io.DataOutputStream;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.*;public class Login extends HttpServlet
{ private static final String CONTENT_TYPE = "text/html; charset=GBK"; public Login()
{
} public void init()
throws ServletException
{
} public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html; charset=GBK");
java.io.PrintWriter out = response.getWriter();
String input = request.getParameter("textfield");
String output = "First test" + input;
//DataOutputStream dos = new DataOutputStream(response.getOutputStream());
//dos.writeUTF(output);
request.setAttribute("output",output);
//response.callPage("/test.jsp", request);
//response.sendRedirect("test.jsp");
RequestDispatcher a = request.getRequestDispatcher("test.jsp");
a.forward(request,response);
} public void destroy()
{
}
}
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.io.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>测试</title>
</head><body>
<form name="frm" action="login" method="get">
<input type="text" name="textfield">
<input name="OK" type="submit" value="提交Servlet">
</form>
<% String is = (String)request.getAttribute("output");
if (is == null)
{
}
else
{
out.println(is);
}
%>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>untitled11.Login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
</web-app>