request.getParameter("companyName"); is to obtain the data submitted by the form (the name is companyName in the front page form)
request.getAttribute("cc") is to get the data of your setAttribute (the value obtained is the value of the parameter cc that you saved yourself.)
Used for parameters in hyperlinks. . request.getParameter(parameter name)
The HttpServletRequest class has both the getAttribute() method and the getParameter() method. The two methods have the following differences:
(1) The HttpServletRequest class has a setAttribute() method but no setParameter() method
(2) When there is a link relationship between two Web components, the linked component obtains the request parameters through the getParameter() method. For example, assuming that there is a link relationship between welcome.jsp and authenticate.jsp, welcome.jsp has the following Code:
<a href="authenticate.jsp?username=weiqin">authenticate.jsp </a>
or:
<form name="form1" method="post" action="authenticate.jsp">
Please enter user name: <input type="text" name="username">
<input type="submit" name="Submit" value="Submit">
</form>
Obtain the request parameter username through the request.getParameter("username") method in authenticate.jsp:
<% String username=request.getParameter("username"); %>
(3) When there is a forwarding relationship between two Web components, the forwarding target component shares the data within the request range with the forwarding source component through the getAttribute() method. It is assumed that there is a forwarding relationship between authenticate.jsp and hello.jsp. authenticate.jsp hopes to pass the current user name to hello.jsp. How to pass this data? First call the setAttribute() method in authenticate.jsp:
<%
String username=request.getParameter("username");
request.setAttribute("username", username);
%>
<jsp:forward page="hello.jsp" />
Obtain the user name through the getAttribute() method in hello.jsp:
<% String username=(String)request.getAttribute("username"); %>
Hello: <%=username %>
Considering at a deeper level, the data passed by the request.getParameter() method will be passed from the Web client to the Web server, representing HTTP request data. The request.getParameter() method returns String type data.
The data passed by the request.setAttribute() and getAttribute() methods will only exist inside the Web container and be shared between Web components with a forwarding relationship. These two methods can set shared data of type Object
To put it simply, the request.getParamenter() method uses the HTTP protocol to transfer data and can only transfer String type information, while the request.setAttribtute() method transfers data in the WEB container and can forward any type of object information. For example, if a listAction servlet wants to pass a LIST collection to list.jsp, it must use setAttribute.