Parameters cannot be resolved in servlets

女生的网名这么多〃 提交于 2019-12-25 03:14:29

问题


I am tryin to get the credentials from jsp page-index.jsp In my servlet-LoginServletwhen under package dao i use

String userName = request.getParameter(usrnm_gtalk);
String password = request.getParameter(password_gtalk);

it says usrnm_gtalk and password_gtalk cannot be resolved.

in my jsp

<form name="LoginForm" method="post" action="/dao/LoginServlet>   
<input type="text" name="usrnm_gtalk"/>
<input type="password" name="password_gtalk" />

web.xml

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>LoginServlet</display-name>
    <servlet-name>LoginServlet</servlet-name>
    <servlet-class>dao.LoginServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>LoginServlet</servlet-name>
    <url-pattern>/Login</url-pattern>
  </servlet-mapping>

i have the servlet-api jar in the lib as well as build path

can anyone point out wat is the problem Thanks


回答1:


You need to represent them as strings, with doublequotes, not as non-existing variables (as the compiler is trying to tell you).

String userName = request.getParameter("usrnm_gtalk"); 
String password = request.getParameter("password_gtalk");

See also:

  • The Java Tutorials - Strings
  • Servlets info page - contains a little hello world


来源:https://stackoverflow.com/questions/5527478/parameters-cannot-be-resolved-in-servlets

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!