java

package helloworld;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; /**
* Servlet implementation class HelloWorld
*/
@WebServlet("/HelloWorld")
public class HelloWorld extends HttpServlet {
private static final long serialVersionUID = 1L; /**
* Default constructor.
*/
public HelloWorld() {
// TODO Auto-generated constructor stub } /**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html; charset=gb2312"); //设置网页的字符编码格式为gb2312
request.setAttribute("msg", "123345"); //类似<key,value>,用于请求的参数传递,一般是action到jsp界面
request.getRequestDispatcher("msg.jsp").forward(request,response);//当你要跳转页面但是你又要用到前一个页面的某些信息的时候可以用这个方法
//当你要跳转页面并且不需要用到前一个页面的信息时你可以选择用redirect(重定向) } }

jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.List" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%=request.getAttribute("msg") %>
</body>
</html>

xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>helloworld</display-name>
<servlet>
<servlet-name>Register</servlet-name>
<servlet-class>helloworld.HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Register</servlet-name>
<url-pattern>/Register</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

servlet 传值给 jsp的更多相关文章

  1. JSP与Servlet传值及对比

    JSP是Servlet技术的扩展,本质上是Servlet的简易方式,更强调应用的外表表达. JSP编译后是”类servlet”. Servlet和JSP最主要的不同点在于,Servlet的应用逻辑是在 ...

  2. 从jsp页面到servlet传值的不同方式

    1.利用超链接<a></a>来传递参数 例如: <td><a href="/month811/Servlet?id=${student.id}&am ...

  3. Struts2如何传值到jsp页面

    Struts2如何传值到jsp页面 不是action传值到jsp页面,而是jsp页面获取action中的属性值,或者范围(如request,session,application等)里的值.所以,有两 ...

  4. Servlet转发到JSP页面的路径问题

    一.现象与概念 1. 问题 在Servlet转发到JSP页面时,此时浏览器地址栏上显示的是Servlet的路径,而若JSP页面的超链接还是相对于该JSP页面的地址且该Servlet和该JSP页面不在同 ...

  5. Struts2.5 利用Ajax将json数据传值到JSP

    AJAX +JSON=>JSP AJAX AJAX 是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术. 通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新.这意味着 ...

  6. springmvc用model传值到jsp页面,el表达式引用接收不到传递过来的值

    springmvc用model传值到jsp页面,el表达式引用接收不到传递过来的值 查看下controller层代码可以发现,写的是没有错误的. @RequestMapping("list. ...

  7. Servlet通过JavaBean传值到JSP页面

    主要通过Attribute进行传递,主要代码如下: 赋值,并定义跳转的页面: request.setAttribute("user", user); request.getRequ ...

  8. JSP通过URL给Servlet传值

    jsp传数据: <a id="a1" href="" ></a> <script> $("#a1").a ...

  9. ajax从jsp向servlet传值

    function Delete(s){ xmlHttp=new XMLHttpRequest(); var url = "/emp/FindSpecial?selcol=" +s; ...

随机推荐

  1. webpack配置构建环境问题汇总

    环境:node 6.9.5  npm 3.10.10 问题一:Module build failed: TypeError: Path must be a string. Received undef ...

  2. [ubuntu Setup] ubuntu 14.10 安装 JDK

    from :  http://www.cnblogs.com/plinx/archive/2013/06/01/3113106.html 1.到 Sun 的官网下载 http://www.oracle ...

  3. Shell实现多级菜单系统安装维护脚本实例分享

    Shell实现多级菜单系统安装维护脚本实例分享 这篇文章主要介绍了Shell实现多级菜单系统安装维护脚本实例分享,本文脚本用多级菜单实现管理WEB服务器.Mysql服务器.Nginx服器等,需要的朋友 ...

  4. Excel的列数以数字格式查看

    1.Excel中的列数默认是以字母形式显示的,当我们有大量数据并想知道任一数据是第多少行多少列时这样就不方便了,我们可以通过如下设置来达到让EXCEL以数字形式显示行数和列数的效果. 2.点击文件-- ...

  5. 【面试问题】—— 2019.3月前端面试之JS原理&CSS基础&Vue框架

    前言:三月中旬面试了两家公司,一家小型公司只有面试,另一家稍大型公司笔试之后一面定夺.笔试部分属于基础类型,网上的复习资料都有. 面试时两位面试官都有考到一些实际工作中会用到,但我还没接触过的知识点. ...

  6. &lt;LeetCode OJ&gt; 101. Symmetric Tree

    101. Symmetric Tree My Submissions Question Total Accepted: 90196 Total Submissions: 273390 Difficul ...

  7. [TypeScript] Infer the Return Type of a Generic Function Type Parameter

    When working with conditionals types, within the “extends” expression, we can use the “infer” keywor ...

  8. react-native 模仿原生 实现下拉刷新/上拉加载更多(RefreshListView)

    1.下拉刷新/上拉加载更多 组件(RefreshListView) src/components/RefreshListView/index.js /** * 下拉刷新/上拉加载更多 组件(Refre ...

  9. 《Mining the Web:Transforming Customer Data into Customer Value》读后札记

    <Mining the Web:Transforming Customer Data into Customer Value> <Web数据挖掘:将客户数据转化为客户价值> — ...

  10. hiredis学习整理

    hiredis安装 http://blog.csdn.net/aizquan/article/details/20777453 http://blog.csdn.net/zhwei_87/articl ...