Home > Web Front-end > HTML Tutorial > 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
Release: 2016-06-24 12:14:26
Original
1307 people have browsed it

jsp code:

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


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="<%request.setAttribute("type","diary"); %>", 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. .

<%request.setAttribute('type','diary'); %>Try 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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template