问题描述
我正在使用jsp,servlet和java做一个网站。我在同一个Jsp页面(Login.jsp)中有两个按钮(登录和注销)。它的方法(loginSession和logoutSession)也在同一个servlet文件(GetServlet.java)中。我的问题是如何将登录按钮连接到loginSesssion并注销按钮到logoutSession?
Im doing a website using jsp,servlet and java. I have two buttons (login and logout) in the same Jsp page(Login.jsp).it's methods (loginSession and logoutSession) are in same servlet file(GetServlet.java) also. my question is how to connect login button to loginSesssion and logout button to logoutSession?
推荐答案
String type request.getParameter("ReqType")
if("LOGOUT".equals(type)){
//do logout operation
}else if("LOGIN".equals(type)){
//do login operation
}
处理2
=============
1.假设请求的网址为
http:// localhost:8080 / login
http:// localhost:8080 / logout
2.在web.xml文件中添加两个url模式指向相同的servlet
3.阅读servlet中的Uri信息
Process 2
=============
1. Assume that requested url are
http://localhost:8080/login
http://localhost:8080/logout
2. add both url pattern in you web.xml file to point the same servlet
3.And read the Uri info in servlet
String uri = request.getRequestURI();
if("/login".equals(uri)){
//do login operation
}else if("/logout".equals(uri)){
//do logout operation
}
<![CDATA[<%@page import="com.mobitel.bankdemo.web.GetSession"%>]]>
<![CDATA[<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>]]>
<![CDATA[<%@page import="com.mobitel.bankdemo.web.GetSession"%>]]>
<![CDATA[<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>]]>
这篇关于同一个Jsp中的两个按钮连接到两个方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!