| | |
Help with 301 redirect code - jsp in url
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2005
Posts: 9
Reputation:
Solved Threads: 0
I'm trying to set a 301 redirect in my jsp code (this is tomcat btw) using this:
<%
response.setContentType("text/html");
response.setDateHeader("Expires", 0);
response.setHeader("Location", "http://www.mysite.com/record/pleasehelpme /helpmeheretoo");
response.setStatus(301);
%>
the pleasehelpme and helpmeheretoo need to use variable values i get from mysql which i would normally express in the application like
<%=(((Recordset1_data = Recordset1.getObject("avariable"))==null || Recordset1.wasNull())?"":Recordset1_data)%>
so what do i need to stick in those parts of the path in the url?
it works great redirecting to a flat url but I need those variable (well, that's the point of this anyway).
sticking the <%= recordset stuff %> is breaking since it's like a tag in a tag (i guess) - have tried variations on sticking println around (String)Recordset1.getObject("avariable") like
"http://www.mysite.com/record/(out.println(String)Recordset1.getObject("avariable"))"
and variations with curly braces and semicolons and everything but i keep getting
Syntax error on token "avalue", invalid AssignmentOperator
errors. (i'm obviously tring to figure out just one variable before i stick both in the path while i get this figured out).
can someone hit me with a clue stick?
<%
response.setContentType("text/html");
response.setDateHeader("Expires", 0);
response.setHeader("Location", "http://www.mysite.com/record/pleasehelpme /helpmeheretoo");
response.setStatus(301);
%>
the pleasehelpme and helpmeheretoo need to use variable values i get from mysql which i would normally express in the application like
<%=(((Recordset1_data = Recordset1.getObject("avariable"))==null || Recordset1.wasNull())?"":Recordset1_data)%>
so what do i need to stick in those parts of the path in the url?
it works great redirecting to a flat url but I need those variable (well, that's the point of this anyway).
sticking the <%= recordset stuff %> is breaking since it's like a tag in a tag (i guess) - have tried variations on sticking println around (String)Recordset1.getObject("avariable") like
"http://www.mysite.com/record/(out.println(String)Recordset1.getObject("avariable"))"
and variations with curly braces and semicolons and everything but i keep getting
Syntax error on token "avalue", invalid AssignmentOperator
errors. (i'm obviously tring to figure out just one variable before i stick both in the path while i get this figured out).
can someone hit me with a clue stick?
•
•
Join Date: Aug 2005
Posts: 216
Reputation:
Solved Threads: 8
•
•
•
•
Originally Posted by bsmith
I'm trying to set a 301 redirect in my jsp code (this is tomcat btw) using this:
<%
response.setContentType("text/html");
response.setDateHeader("Expires", 0);
response.setHeader("Location", "http://www.mysite.com/record/pleasehelpme /helpmeheretoo");
response.setStatus(301);
%>
the pleasehelpme and helpmeheretoo need to use variable values i get from mysql which i would normally express in the application like
<%=(((Recordset1_data = Recordset1.getObject("avariable"))==null || Recordset1.wasNull())?"":Recordset1_data)%>
so what do i need to stick in those parts of the path in the url?
it works great redirecting to a flat url but I need those variable (well, that's the point of this anyway).
sticking the <%= recordset stuff %> is breaking since it's like a tag in a tag (i guess) - have tried variations on sticking println around (String)Recordset1.getObject("avariable") like
"http://www.mysite.com/record/(out.println(String)Recordset1.getObject("avariable"))"
and variations with curly braces and semicolons and everything but i keep getting
Syntax error on token "avalue", invalid AssignmentOperator
errors. (i'm obviously tring to figure out just one variable before i stick both in the path while i get this figured out).
can someone hit me with a clue stick?
You post is very confusing...but my guess is you need to do the following in your code...
JSP Syntax (Toggle Plain Text)
// As long as there is a Recordset1 object by this time... <% String variable1 = (String)Recordset1.getObject("avariable") %> <% String variable2 = (String)Recordset2.getObject("avariable") %> <% String url = "http://www.mysite.com/record" + variable1 + "/" + variable2 %> <% response.setContentType("text/html"); response.setDateHeader("Expires", 0); response.setHeader("Location", url); response.setStatus(301); %>
Regards,
Nate
![]() |
Similar Threads
- custom .htaccess file 301 Redirect to non www form (Search Engine Optimization)
- 301 redirect URLs in asp? (ASP)
- custom .htaccess file 301 Redirect to non www form Prolems (Search Engine Optimization)
- 301 redirect (Windows NT / 2000 / XP)
- Move out java code from jsp (Java)
Other Threads in the JSP Forum
- Previous Thread: javascript variable in jsp session
- Next Thread: How do I pass data from a recordset on asp page towards an array on js file
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish imagetodatabse imageupload internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial video web





