Home  >  Article  >  Web Front-end  >  servlet cannot get the parameters passed in jsp_html/css_WEB-ITnose

servlet cannot get the parameters passed in jsp_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:14:261273browse

jsp code:

<a  href="<%= request.getContextPath()%>/DiaryListServlet" title="日记" target="mainFrame" class="diary" onclick="<%request.setAttribute("type","diary"); %>"><font							class="dropmenu_text">日记</font>						</a>


In servlet, System.out.println(request.getAttribute("type")); What is printed is null. Why? How to solve it. Only one page is passed to the servlet. So there is no need to forward it


Reply to the discussion (solution)

Luzhu Are you in the wrong place? ? ? ? ? I haven’t done Java for a long time. I suggest you splice it directly behind your href, and then use request.getParameter(key) in the servelt to get the value. Which onclick do you use like this? This should trigger an event, right? ? ? ? ? Instead of assigning values ​​to the attributes in your request

use the & symbol to link it!

The sentence you wrote, onclick="695c61208a3a3d7ff8b7792aa0287015", whether you click it or not, the jsp will be executed during compilation. Even if there is no problem, you still need to pay attention to the quotation marks. .

011efa2914806b0c90f36fc5289d7646Try again like this, but this does not mean that it is the result after you click.

Dear, you can’t play like this. In jsp, java is always compiled first. Do you think it is feasible to convert your code into js form? Generally, when written this way, the encapsulated data processed by the action is sent to the page, and then displayed during loading, right? If you want onclick to pass a value, then you have to construct a click function in the form of js, and splice your parameters on the href

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn