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. React Conf 2017 干货总结 1: React + ES next = ♥

    React Conf 2017在加利福尼亚州的圣克拉拉万豪酒店圆满落幕,这已经是Facebook举办的第三届React官方大会了.虽然不能参会,但是作为前端开发者,我们当然不能错过这个绝佳的学习契机. ...

  2. 【k8s】了解一下k8s

    了解一下k8s 地址: https://www.kubernetes.org.cn/doc-11

  3. Linux GPRS模块问题

    这是一个硬件问题,不过被我这个学软件的给遇到了.很尴尬,纠结了很久. GPRS模块如果没有插上sim卡,开机之后一切正常.一旦插上卡之后开机大约过十秒钟之后会自动关机.并在串口上面打印一下信息: II ...

  4. Linux中C语言的编程

    编译的过程 编译的概念:编译程序读取源程序(字符流),对之进行词法与语法的分析,将高级语言指令转换成功能等效的汇编代码,再由汇编程序转换成机器语言,并且按照操作系统对可执行文件格式的要求链接成可执行程 ...

  5. centos和ubuntu下pycharm无法输入中文的解决办法

    编辑启动的脚本文件 vim /usr/bin/pycharm ubuntu下添加 export GTK_IM_MODULE=fcitx export QT_IM_MODULE=fcitx export ...

  6. Laravel 5 系列教程三:视图变量传递和Blade

    免费视频教程地址https://laravist.com/series/laravel-5-basic 上一篇我们简单地说了Router,Views和Controllers的工作流程,这一次我就按照上 ...

  7. javascript专业八级测试答案整理

    前几天社区的群里森破发了一个这样的链接: http://ourjs.com/detail/52fb82e13bd19c4814000001 做了一遍后突然对人生感到了迷茫,本着不能只有我一个人伤心的原 ...

  8. netty handlers模式

    netty的handler模式真的挺方便的,可以像插件一样随意的插入自己新增的功能而不用队系统进行大的变动. 下面我们来看一下这个模式是如何实现和运行的. 待续...

  9. No goals have been specified for this build 解决方案

    运行maven报错:[ERROR] No goals have been specified for this build. You must specify a valid lifecycle ph ...

  10. 使用网桥模式(bridge networking mode)配置KVM-QUME虚拟机网络

    (1)linux要工作在网桥模式,所以必须安装两个RPM包.即:bridge-utils和tunctl.它们提供所需的brctl.tunctl命令行工具.能够使用yum在线安装: [root@serv ...