0

您好我正在尝试将数据从 servlet 传递到 jsp 页面,但得到一个空值。请告诉我哪里出错了?这是我的代码:

MyConnection.java

  public void doGet (HttpServletRequest inRequest,
             HttpServletResponse outResponse) throws ServletException,
             IOException {
 
             inRequest.setAttribute ("ST", "QWERTY");
             RequestDispatcher dispatcher = inRequest.getRequestDispatcher ("/index.jsp");
 
             out.print ("\ n" + dispatcher);
 
             dispatcher.forward (inRequest, outResponse);
}

索引.jsp

<% @ page contentType = "text / html" pageEncoding = "UTF-8"%>
<% @ page language = "java" import = "java.util. *"%>
<! DOCTYPE html>
<html>
     <head>
         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
         <title> JSP Page </ title>
     </ head>
     <body>
         <form action="MyConnection" name = "myForm" method="Get">
             <% = (String) request.getAttribute ("ST")%>
             <% out.println (request.getAttribute ("ST"));%>
         </ form>
     </ body>
</ html>
4

1 回答 1

0

浏览器中的地址就是JSP的地址,所以JSP被执行了。要执行 servlet,您必须将 servlet 的地址放在地址栏中。

于 2013-06-02T12:51:20.483 回答