otak info official Logo   
OTAK.INFO
Personal Blog

Hariyanto Lim

정길상 / 鄭吉祥
Home   Last Posts  
 
Please login to see more topics and discussion categories.
 
goto main category list >> Software programming >> ServLet

Title : Pass processed value from ServLet to JSP
Total Reply : 0
Total View : 4704


Harry
Harry
Total thread: 131
Total reply: 50

Post #120
Pass processed value from ServLet to JSP
When we need to pass some parameters from ServLet to JSP or other ServLet then we can use:
public class MyServLet extends HttpServlet {
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    // get the parameter
    String data = req.getParameter("data");

    // create a new parameter "mydata" to send to the other JSP/ServLet
    req.setAttribute("mydata", "harry " + Calendar.getInstance().get(Calendar.MILLISECOND));

    req.getRequestDispatcher("/WEB-INF/Myjsp.jsp").forward(req,  resp);
  }
}
In our "/WEB-INF/Myjsp.jsp"
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<html lang="en-US" xml:lang="ko-KR" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My web title</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
Hello World
<br />
My data value is <%=mydata %>
</body>
</html>
Falling in love with the world

Write : 2013-07-18 11:51:12
Last edit : 2013-07-18 11:51:56

If you want to create a new reply then please login first.



www.OTAK.INFO
Since 19 January 2007
Page hit : 712,071

Code update 24th June 2013
Brain is a very capable to solve big problems
but requires constant reminders about how to.
peace bird