14 个解决方案
#1
request.getParameter("BoardID");无法获得嘛??
#2
是的,是null值,为什么?
#3
把你传参到servlet那句贴出来
#4
主要的思路是servlet根据页面的不同取不同的参数进行处理
--------------------------------------
package forum;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.*;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
public class ControlCenter extends HttpServlet {
public void doGet(HttpServletRequest request ,
HttpServletResponse response)
throws ServletException , IOException {
PrintWriter out = response.getWriter();
String ResourcePage = request.getParameter("RescourcePage");
int AimProcess = 0,
ReturnValue = 1;
if (ResourcePage == "register") {
AimProcess = 0;//用户注册
out.print(AimProcess);
} else if (ResourcePage == "NewTopic") {
AimProcess = 1;//发表新主题
out.print("it is new topic");
} else {
out.print("the request page is null");
}
switch (AimProcess) {
case 0 : {
String UserName = new String(request.getParameter("UserName").getBytes("ISO8859_1"),"GB2312"),
email = new String(request.getParameter("email").getBytes("ISO8859_1"),"GB2312"),
password = new String(request.getParameter("pwd").getBytes("ISO8859_1"),"GB2312"),
RealName = new String(request.getParameter("RealName").getBytes("ISO8859_1"),"GB2312"),
sex = new String(request.getParameter("sex").getBytes("ISO8859_1"),"GB2312"),
ComeFrom = new String(request.getParameter("ComeFrom").getBytes("ISO8859_1"),"GB2312"),
birthday = new String(request.getParameter("birthday").getBytes("ISO8859_1"),"GB2312"),
qq = new String(request.getParameter("qq").getBytes("ISO8859_1"),"GB2312"),
mobile = new String(request.getParameter("mobile").getBytes("ISO8859_1"),"GB2312"),
SignInfo = new String(request.getParameter("SignInfo").getBytes("ISO8859_1"),"GB2312");
forum.register RegisterUser = new forum.register();
RegisterUser.setUserName(UserName);
RegisterUser.setEmail(email);
RegisterUser.setPwd(password);
RegisterUser.setRealName(RealName);
RegisterUser.setSex(sex);
RegisterUser.setComeFrom(ComeFrom);
RegisterUser.setBirthday(birthday);
RegisterUser.setQq(qq);
RegisterUser.setMobile(mobile);
RegisterUser.setSignInfo(SignInfo);
try {
ReturnValue = RegisterUser.registerUser();
} catch(Exception e) {
out.print("servlet compile error : " + e.getMessage());
}
if (ReturnValue == 0) {
response.sendRedirect("../MyBBS.jsp");
} else {
response.sendRedirect("../error.jsp?ErrorNo=" + ReturnValue);
}
break;
}//注册
case 1 : {
//这里是取BoardID的
HttpSession session = request.getSession();
String BoardID = request.getParameter("BoardID");
String CurrentUserName = (String)session.getAttribute("UserName");
if (CurrentUserName == null) {
response.sendRedirect("../login.jsp?AimPage=NewTopic.jsp?BoardID=" + BoardID);
} else {
response.sendRedirect("../NewTopic.jsp?BoardID=" + BoardID);
}
break;
}//发表新主题
case 2 : {
HttpSession session = null;
String AimPage = request.getParameter("AimPage"),
UserName = new String(request.getParameter("UserName").getBytes("ISO8859_1"),"GB2312"),
password = request.getParameter("password");
forum.login login = new forum.login();
login.setUserName(UserName);
try {
if (login.isUserExist() == 6) {
response.sendRedirect("../error.jsp?ErrorNo=6");
} else {
login.setPassword(password);
if (login.isPasswordValid() == 7) {
response.sendRedirect("../error.jsp?ErrorNo=7");
} else {
session.setAttribute(UserName , UserName);
response.sendRedirect("../" + AimPage);
}
}
} catch(Exception e) {
response.sendRedirect("../error.jsp?ErrorNo=-2");
}
break;
}//登录
case 4 : {
break;
}
case 5 : {
break;
}
}*/
}
public void doPost(HttpServletRequest request ,
HttpServletResponse response)
throws ServletException , IOException {
doGet(request , response);
}
}//end of Servlet
--------------------------------------
package forum;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.*;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
public class ControlCenter extends HttpServlet {
public void doGet(HttpServletRequest request ,
HttpServletResponse response)
throws ServletException , IOException {
PrintWriter out = response.getWriter();
String ResourcePage = request.getParameter("RescourcePage");
int AimProcess = 0,
ReturnValue = 1;
if (ResourcePage == "register") {
AimProcess = 0;//用户注册
out.print(AimProcess);
} else if (ResourcePage == "NewTopic") {
AimProcess = 1;//发表新主题
out.print("it is new topic");
} else {
out.print("the request page is null");
}
switch (AimProcess) {
case 0 : {
String UserName = new String(request.getParameter("UserName").getBytes("ISO8859_1"),"GB2312"),
email = new String(request.getParameter("email").getBytes("ISO8859_1"),"GB2312"),
password = new String(request.getParameter("pwd").getBytes("ISO8859_1"),"GB2312"),
RealName = new String(request.getParameter("RealName").getBytes("ISO8859_1"),"GB2312"),
sex = new String(request.getParameter("sex").getBytes("ISO8859_1"),"GB2312"),
ComeFrom = new String(request.getParameter("ComeFrom").getBytes("ISO8859_1"),"GB2312"),
birthday = new String(request.getParameter("birthday").getBytes("ISO8859_1"),"GB2312"),
qq = new String(request.getParameter("qq").getBytes("ISO8859_1"),"GB2312"),
mobile = new String(request.getParameter("mobile").getBytes("ISO8859_1"),"GB2312"),
SignInfo = new String(request.getParameter("SignInfo").getBytes("ISO8859_1"),"GB2312");
forum.register RegisterUser = new forum.register();
RegisterUser.setUserName(UserName);
RegisterUser.setEmail(email);
RegisterUser.setPwd(password);
RegisterUser.setRealName(RealName);
RegisterUser.setSex(sex);
RegisterUser.setComeFrom(ComeFrom);
RegisterUser.setBirthday(birthday);
RegisterUser.setQq(qq);
RegisterUser.setMobile(mobile);
RegisterUser.setSignInfo(SignInfo);
try {
ReturnValue = RegisterUser.registerUser();
} catch(Exception e) {
out.print("servlet compile error : " + e.getMessage());
}
if (ReturnValue == 0) {
response.sendRedirect("../MyBBS.jsp");
} else {
response.sendRedirect("../error.jsp?ErrorNo=" + ReturnValue);
}
break;
}//注册
case 1 : {
//这里是取BoardID的
HttpSession session = request.getSession();
String BoardID = request.getParameter("BoardID");
String CurrentUserName = (String)session.getAttribute("UserName");
if (CurrentUserName == null) {
response.sendRedirect("../login.jsp?AimPage=NewTopic.jsp?BoardID=" + BoardID);
} else {
response.sendRedirect("../NewTopic.jsp?BoardID=" + BoardID);
}
break;
}//发表新主题
case 2 : {
HttpSession session = null;
String AimPage = request.getParameter("AimPage"),
UserName = new String(request.getParameter("UserName").getBytes("ISO8859_1"),"GB2312"),
password = request.getParameter("password");
forum.login login = new forum.login();
login.setUserName(UserName);
try {
if (login.isUserExist() == 6) {
response.sendRedirect("../error.jsp?ErrorNo=6");
} else {
login.setPassword(password);
if (login.isPasswordValid() == 7) {
response.sendRedirect("../error.jsp?ErrorNo=7");
} else {
session.setAttribute(UserName , UserName);
response.sendRedirect("../" + AimPage);
}
}
} catch(Exception e) {
response.sendRedirect("../error.jsp?ErrorNo=-2");
}
break;
}//登录
case 4 : {
break;
}
case 5 : {
break;
}
}*/
}
public void doPost(HttpServletRequest request ,
HttpServletResponse response)
throws ServletException , IOException {
doGet(request , response);
}
}//end of Servlet
#5
关键在于ResourcePage传进来也是null
#6
改成这样
if(ResourcePage == null)
{
out.print("the request page is null");
}
else
{
if (ResourcePage.equals("register")) {
AimProcess = 0;//用户注册
out.print(AimProcess);
}
else if (ResourcePage.equals("NewTopic")) {
AimProcess = 1;//发表新主题
out.print("it is new topic");
}
}
if(ResourcePage == null)
{
out.print("the request page is null");
}
else
{
if (ResourcePage.equals("register")) {
AimProcess = 0;//用户注册
out.print(AimProcess);
}
else if (ResourcePage.equals("NewTopic")) {
AimProcess = 1;//发表新主题
out.print("it is new topic");
}
}
#7
to : wjfxiao(野渡无人舟自横)
你提供的方法和我写的差不多,我现在想要解决的问题不在于此而是想知道为何servlet不能通过url传递参数,并找到解决的办法。不过,还是要谢谢你。
你提供的方法和我写的差不多,我现在想要解决的问题不在于此而是想知道为何servlet不能通过url传递参数,并找到解决的办法。不过,还是要谢谢你。
#8
没听明白你说什么。
NewTopic.jsp?BoardID=1
肯定只有在NewTopic.jsp中才能request.getParameter("BoardID")成功,
这跟servlet有什么关系?
如果说照这个样子写<a href="servlet?BoardID=1">xx</a>你在servlet中还取不到,那才稀奇了。
NewTopic.jsp?BoardID=1
肯定只有在NewTopic.jsp中才能request.getParameter("BoardID")成功,
这跟servlet有什么关系?
如果说照这个样子写<a href="servlet?BoardID=1">xx</a>你在servlet中还取不到,那才稀奇了。
#9
你连BoardID=1都没有传给servlet,你叫servlet怎么取BoardID=1????
#10
attributes are reset in requests.
you can put it in session
you can put it in session
#11
我的URL链接是<a href="ControlCenter?NewTopic.jsp&BoardID=1">××</a>
这样传进去的是空值,可以用getQueryString获取NewTopic.jsp?BoardID=1字符串,但是request.Parameters怎么弄都是空值~~~
这样传进去的是空值,可以用getQueryString获取NewTopic.jsp?BoardID=1字符串,但是request.Parameters怎么弄都是空值~~~
#12
顶,隔半小时提前一次怎么还是报“提前太频繁”??
#13
<a href="/servlet/yourServlet?BoardID=1"> ***</a>
这样在servlet里肯定是可以用request.getParameter("BoardID")来获得的!!!!!
这样在servlet里肯定是可以用request.getParameter("BoardID")来获得的!!!!!
#14
把"."转换成其他字符。
#1
request.getParameter("BoardID");无法获得嘛??
#2
是的,是null值,为什么?
#3
把你传参到servlet那句贴出来
#4
主要的思路是servlet根据页面的不同取不同的参数进行处理
--------------------------------------
package forum;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.*;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
public class ControlCenter extends HttpServlet {
public void doGet(HttpServletRequest request ,
HttpServletResponse response)
throws ServletException , IOException {
PrintWriter out = response.getWriter();
String ResourcePage = request.getParameter("RescourcePage");
int AimProcess = 0,
ReturnValue = 1;
if (ResourcePage == "register") {
AimProcess = 0;//用户注册
out.print(AimProcess);
} else if (ResourcePage == "NewTopic") {
AimProcess = 1;//发表新主题
out.print("it is new topic");
} else {
out.print("the request page is null");
}
switch (AimProcess) {
case 0 : {
String UserName = new String(request.getParameter("UserName").getBytes("ISO8859_1"),"GB2312"),
email = new String(request.getParameter("email").getBytes("ISO8859_1"),"GB2312"),
password = new String(request.getParameter("pwd").getBytes("ISO8859_1"),"GB2312"),
RealName = new String(request.getParameter("RealName").getBytes("ISO8859_1"),"GB2312"),
sex = new String(request.getParameter("sex").getBytes("ISO8859_1"),"GB2312"),
ComeFrom = new String(request.getParameter("ComeFrom").getBytes("ISO8859_1"),"GB2312"),
birthday = new String(request.getParameter("birthday").getBytes("ISO8859_1"),"GB2312"),
qq = new String(request.getParameter("qq").getBytes("ISO8859_1"),"GB2312"),
mobile = new String(request.getParameter("mobile").getBytes("ISO8859_1"),"GB2312"),
SignInfo = new String(request.getParameter("SignInfo").getBytes("ISO8859_1"),"GB2312");
forum.register RegisterUser = new forum.register();
RegisterUser.setUserName(UserName);
RegisterUser.setEmail(email);
RegisterUser.setPwd(password);
RegisterUser.setRealName(RealName);
RegisterUser.setSex(sex);
RegisterUser.setComeFrom(ComeFrom);
RegisterUser.setBirthday(birthday);
RegisterUser.setQq(qq);
RegisterUser.setMobile(mobile);
RegisterUser.setSignInfo(SignInfo);
try {
ReturnValue = RegisterUser.registerUser();
} catch(Exception e) {
out.print("servlet compile error : " + e.getMessage());
}
if (ReturnValue == 0) {
response.sendRedirect("../MyBBS.jsp");
} else {
response.sendRedirect("../error.jsp?ErrorNo=" + ReturnValue);
}
break;
}//注册
case 1 : {
//这里是取BoardID的
HttpSession session = request.getSession();
String BoardID = request.getParameter("BoardID");
String CurrentUserName = (String)session.getAttribute("UserName");
if (CurrentUserName == null) {
response.sendRedirect("../login.jsp?AimPage=NewTopic.jsp?BoardID=" + BoardID);
} else {
response.sendRedirect("../NewTopic.jsp?BoardID=" + BoardID);
}
break;
}//发表新主题
case 2 : {
HttpSession session = null;
String AimPage = request.getParameter("AimPage"),
UserName = new String(request.getParameter("UserName").getBytes("ISO8859_1"),"GB2312"),
password = request.getParameter("password");
forum.login login = new forum.login();
login.setUserName(UserName);
try {
if (login.isUserExist() == 6) {
response.sendRedirect("../error.jsp?ErrorNo=6");
} else {
login.setPassword(password);
if (login.isPasswordValid() == 7) {
response.sendRedirect("../error.jsp?ErrorNo=7");
} else {
session.setAttribute(UserName , UserName);
response.sendRedirect("../" + AimPage);
}
}
} catch(Exception e) {
response.sendRedirect("../error.jsp?ErrorNo=-2");
}
break;
}//登录
case 4 : {
break;
}
case 5 : {
break;
}
}*/
}
public void doPost(HttpServletRequest request ,
HttpServletResponse response)
throws ServletException , IOException {
doGet(request , response);
}
}//end of Servlet
--------------------------------------
package forum;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.*;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
public class ControlCenter extends HttpServlet {
public void doGet(HttpServletRequest request ,
HttpServletResponse response)
throws ServletException , IOException {
PrintWriter out = response.getWriter();
String ResourcePage = request.getParameter("RescourcePage");
int AimProcess = 0,
ReturnValue = 1;
if (ResourcePage == "register") {
AimProcess = 0;//用户注册
out.print(AimProcess);
} else if (ResourcePage == "NewTopic") {
AimProcess = 1;//发表新主题
out.print("it is new topic");
} else {
out.print("the request page is null");
}
switch (AimProcess) {
case 0 : {
String UserName = new String(request.getParameter("UserName").getBytes("ISO8859_1"),"GB2312"),
email = new String(request.getParameter("email").getBytes("ISO8859_1"),"GB2312"),
password = new String(request.getParameter("pwd").getBytes("ISO8859_1"),"GB2312"),
RealName = new String(request.getParameter("RealName").getBytes("ISO8859_1"),"GB2312"),
sex = new String(request.getParameter("sex").getBytes("ISO8859_1"),"GB2312"),
ComeFrom = new String(request.getParameter("ComeFrom").getBytes("ISO8859_1"),"GB2312"),
birthday = new String(request.getParameter("birthday").getBytes("ISO8859_1"),"GB2312"),
qq = new String(request.getParameter("qq").getBytes("ISO8859_1"),"GB2312"),
mobile = new String(request.getParameter("mobile").getBytes("ISO8859_1"),"GB2312"),
SignInfo = new String(request.getParameter("SignInfo").getBytes("ISO8859_1"),"GB2312");
forum.register RegisterUser = new forum.register();
RegisterUser.setUserName(UserName);
RegisterUser.setEmail(email);
RegisterUser.setPwd(password);
RegisterUser.setRealName(RealName);
RegisterUser.setSex(sex);
RegisterUser.setComeFrom(ComeFrom);
RegisterUser.setBirthday(birthday);
RegisterUser.setQq(qq);
RegisterUser.setMobile(mobile);
RegisterUser.setSignInfo(SignInfo);
try {
ReturnValue = RegisterUser.registerUser();
} catch(Exception e) {
out.print("servlet compile error : " + e.getMessage());
}
if (ReturnValue == 0) {
response.sendRedirect("../MyBBS.jsp");
} else {
response.sendRedirect("../error.jsp?ErrorNo=" + ReturnValue);
}
break;
}//注册
case 1 : {
//这里是取BoardID的
HttpSession session = request.getSession();
String BoardID = request.getParameter("BoardID");
String CurrentUserName = (String)session.getAttribute("UserName");
if (CurrentUserName == null) {
response.sendRedirect("../login.jsp?AimPage=NewTopic.jsp?BoardID=" + BoardID);
} else {
response.sendRedirect("../NewTopic.jsp?BoardID=" + BoardID);
}
break;
}//发表新主题
case 2 : {
HttpSession session = null;
String AimPage = request.getParameter("AimPage"),
UserName = new String(request.getParameter("UserName").getBytes("ISO8859_1"),"GB2312"),
password = request.getParameter("password");
forum.login login = new forum.login();
login.setUserName(UserName);
try {
if (login.isUserExist() == 6) {
response.sendRedirect("../error.jsp?ErrorNo=6");
} else {
login.setPassword(password);
if (login.isPasswordValid() == 7) {
response.sendRedirect("../error.jsp?ErrorNo=7");
} else {
session.setAttribute(UserName , UserName);
response.sendRedirect("../" + AimPage);
}
}
} catch(Exception e) {
response.sendRedirect("../error.jsp?ErrorNo=-2");
}
break;
}//登录
case 4 : {
break;
}
case 5 : {
break;
}
}*/
}
public void doPost(HttpServletRequest request ,
HttpServletResponse response)
throws ServletException , IOException {
doGet(request , response);
}
}//end of Servlet
#5
关键在于ResourcePage传进来也是null
#6
改成这样
if(ResourcePage == null)
{
out.print("the request page is null");
}
else
{
if (ResourcePage.equals("register")) {
AimProcess = 0;//用户注册
out.print(AimProcess);
}
else if (ResourcePage.equals("NewTopic")) {
AimProcess = 1;//发表新主题
out.print("it is new topic");
}
}
if(ResourcePage == null)
{
out.print("the request page is null");
}
else
{
if (ResourcePage.equals("register")) {
AimProcess = 0;//用户注册
out.print(AimProcess);
}
else if (ResourcePage.equals("NewTopic")) {
AimProcess = 1;//发表新主题
out.print("it is new topic");
}
}
#7
to : wjfxiao(野渡无人舟自横)
你提供的方法和我写的差不多,我现在想要解决的问题不在于此而是想知道为何servlet不能通过url传递参数,并找到解决的办法。不过,还是要谢谢你。
你提供的方法和我写的差不多,我现在想要解决的问题不在于此而是想知道为何servlet不能通过url传递参数,并找到解决的办法。不过,还是要谢谢你。
#8
没听明白你说什么。
NewTopic.jsp?BoardID=1
肯定只有在NewTopic.jsp中才能request.getParameter("BoardID")成功,
这跟servlet有什么关系?
如果说照这个样子写<a href="servlet?BoardID=1">xx</a>你在servlet中还取不到,那才稀奇了。
NewTopic.jsp?BoardID=1
肯定只有在NewTopic.jsp中才能request.getParameter("BoardID")成功,
这跟servlet有什么关系?
如果说照这个样子写<a href="servlet?BoardID=1">xx</a>你在servlet中还取不到,那才稀奇了。
#9
你连BoardID=1都没有传给servlet,你叫servlet怎么取BoardID=1????
#10
attributes are reset in requests.
you can put it in session
you can put it in session
#11
我的URL链接是<a href="ControlCenter?NewTopic.jsp&BoardID=1">××</a>
这样传进去的是空值,可以用getQueryString获取NewTopic.jsp?BoardID=1字符串,但是request.Parameters怎么弄都是空值~~~
这样传进去的是空值,可以用getQueryString获取NewTopic.jsp?BoardID=1字符串,但是request.Parameters怎么弄都是空值~~~
#12
顶,隔半小时提前一次怎么还是报“提前太频繁”??
#13
<a href="/servlet/yourServlet?BoardID=1"> ***</a>
这样在servlet里肯定是可以用request.getParameter("BoardID")来获得的!!!!!
这样在servlet里肯定是可以用request.getParameter("BoardID")来获得的!!!!!
#14
把"."转换成其他字符。